@medusajs/loyalty-plugin 0.0.1
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/.medusa/server/src/admin/components/action-menu.js +63 -0
- package/.medusa/server/src/admin/components/chip-group.js +82 -0
- package/.medusa/server/src/admin/components/chip-input.js +157 -0
- package/.medusa/server/src/admin/components/combobox.js +324 -0
- package/.medusa/server/src/admin/components/conditional-tooltip.js +15 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-boolean-cell.js +66 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-cell-container.js +77 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-currency-cell.js +110 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-duplicate-cell.js +16 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-keyboard-shortcut-modal.js +214 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-number-cell.js +77 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-readonly-cell.js +32 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-root.js +743 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-row-error-indicator.js +37 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-skeleton.js +54 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-text-cell.js +66 -0
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-toggleable-number-cell.js +166 -0
- package/.medusa/server/src/admin/components/data-grid/components/index.js +16 -0
- package/.medusa/server/src/admin/components/data-grid/context/data-grid-context.js +7 -0
- package/.medusa/server/src/admin/components/data-grid/context/index.js +6 -0
- package/.medusa/server/src/admin/components/data-grid/context/use-data-grid-context.js +14 -0
- package/.medusa/server/src/admin/components/data-grid/data-grid.js +31 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-column-helper.js +28 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-price-columns.js +85 -0
- package/.medusa/server/src/admin/components/data-grid/helpers/index.js +6 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/index.js +31 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-error.js +50 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-handlers.js +123 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-metadata.js +52 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-snapshot.js +43 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell.js +191 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-clipboard-events.js +70 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-column-visibility.js +51 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-duplicate-cell.js +15 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-error-highlighting.js +86 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-form-handlers.js +149 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-keydown-event.js +482 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-mouse-up-event.js +64 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-navigation.js +81 -0
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-query-tool.js +14 -0
- package/.medusa/server/src/admin/components/data-grid/index.js +8 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-bulk-update-command.js +27 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-matrix.js +296 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-query-tool.js +62 -0
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-update-command.js +25 -0
- package/.medusa/server/src/admin/components/data-grid/models/index.js +10 -0
- package/.medusa/server/src/admin/components/data-grid/types.js +1 -0
- package/.medusa/server/src/admin/components/data-grid/utils.js +18 -0
- package/.medusa/server/src/admin/components/data-table/components/data-table-status-cell/data-table-status-cell.js +36 -0
- package/.medusa/server/src/admin/components/data-table/data-table.js +271 -0
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-columns.js +51 -0
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-filters.js +90 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/index.js +10 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-columns.js +48 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-empty-state.js +19 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-filters.js +30 -0
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-query.js +23 -0
- package/.medusa/server/src/admin/components/data-table/index.js +4 -0
- package/.medusa/server/src/admin/components/data-table.js +249 -0
- package/.medusa/server/src/admin/components/display-id.js +18 -0
- package/.medusa/server/src/admin/components/file-upload.js +116 -0
- package/.medusa/server/src/admin/components/form.js +151 -0
- package/.medusa/server/src/admin/components/handle-input.js +22 -0
- package/.medusa/server/src/admin/components/header.js +41 -0
- package/.medusa/server/src/admin/components/icon-avatar.js +27 -0
- package/.medusa/server/src/admin/components/json-view-section.js +139 -0
- package/.medusa/server/src/admin/components/keybound-form.js +32 -0
- package/.medusa/server/src/admin/components/layouts/single-column.js +7 -0
- package/.medusa/server/src/admin/components/layouts/two-column.js +13 -0
- package/.medusa/server/src/admin/components/listicle.js +20 -0
- package/.medusa/server/src/admin/components/modals/index.js +19 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +57 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +71 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +60 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +30 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +12 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +55 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +63 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +47 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +14 -0
- package/.medusa/server/src/admin/components/placeholder-cell.js +7 -0
- package/.medusa/server/src/admin/components/product/product-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/product-cell/product-cell.js +15 -0
- package/.medusa/server/src/admin/components/product/product-status-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/product-status-cell/product-status-cell.js +18 -0
- package/.medusa/server/src/admin/components/product/sales-channels-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/sales-channels-cell/sales-channels-cell.js +31 -0
- package/.medusa/server/src/admin/components/product/variant-cell/index.js +5 -0
- package/.medusa/server/src/admin/components/product/variant-cell/variant-cell.js +15 -0
- package/.medusa/server/src/admin/components/section-row.js +32 -0
- package/.medusa/server/src/admin/components/sidebar-link.js +31 -0
- package/.medusa/server/src/admin/components/sortable-list.js +152 -0
- package/.medusa/server/src/admin/components/switch-box.js +43 -0
- package/.medusa/server/src/admin/components/tax-badge.js +18 -0
- package/.medusa/server/src/admin/components/thumbnail.js +28 -0
- package/.medusa/server/src/admin/components/upload-media-form-item.js +83 -0
- package/.medusa/server/src/admin/hooks/api/customers.js +26 -0
- package/.medusa/server/src/admin/hooks/api/gift-cards.js +107 -0
- package/.medusa/server/src/admin/hooks/api/order.js +16 -0
- package/.medusa/server/src/admin/hooks/api/price-preferences.js +19 -0
- package/.medusa/server/src/admin/hooks/api/products.js +127 -0
- package/.medusa/server/src/admin/hooks/api/regions.js +17 -0
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +28 -0
- package/.medusa/server/src/admin/hooks/api/store-credit-accounts.js +41 -0
- package/.medusa/server/src/admin/hooks/api/store.js +31 -0
- package/.medusa/server/src/admin/hooks/api/transaction-groups.js +23 -0
- package/.medusa/server/src/admin/hooks/api/transactions.js +23 -0
- package/.medusa/server/src/admin/hooks/commands/use-command-history.js +45 -0
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +59 -0
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +89 -0
- package/.medusa/server/src/admin/hooks/common/use-date.js +32 -0
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +22 -0
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +14 -0
- package/.medusa/server/src/admin/hooks/query/use-customers-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/query/use-transaction-groups-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/sales-channels/index.js +10 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-columns.js +48 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-empty-state.js +19 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-filters.js +30 -0
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-query.js +23 -0
- package/.medusa/server/src/admin/lib/currencies.js +729 -0
- package/.medusa/server/src/admin/lib/query-key.js +17 -0
- package/.medusa/server/src/admin/lib/sdk.js +10 -0
- package/.medusa/server/src/admin/routes/gift-card-products/@create/page.js +75 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/components/gift-card-product-edit-denominations-form.js +172 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/page.js +30 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/components/gift-card-product-edit-form.js +180 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/page.js +30 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-general-section.js +97 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-media-section.js +162 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-sales-channel-section.js +89 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-variant-section.js +199 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/edit-product-media-form.js +353 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/index.js +5 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/product-media-gallery.js +247 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view-context.js +5 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view.js +48 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/use-product-media-view.js +14 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/page.js +28 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/page.js +40 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/prices-edit.js +121 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/variant-pricing-form.js +72 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/page.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/components/edit-sales-channel-form.js +123 -0
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/page.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/general-form-section.js +1 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-denominations-form.js +98 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-details-form.js +28 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-denominations.js +96 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-general.js +90 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-media.js +288 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize-section.js +111 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form.js +285 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-sales-channel-stacked-modal.js +124 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/index.js +4 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/schema.js +112 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/types.js +1 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/columns.js +35 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/filters.js +11 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/gift-card-products-table.js +61 -0
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-card-products/page.js +18 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@expiration/page.js +137 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@note/page.js +87 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/components/transfer-icon.js +352 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/page.js +116 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-balance-section.js +49 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-general-section.js +177 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-note-section.js +27 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-order-section.js +33 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-owner-section.js +33 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-transactions-section.js +18 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/columns.js +50 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-cards/_id_/page.js +78 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-card-products-section.js +40 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/columns.js +57 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/filters.js +13 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/gift-cards-table.js +61 -0
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/query.js +23 -0
- package/.medusa/server/src/admin/routes/gift-cards/page.js +27 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/credit-card-icon.js +126 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-balance-section.js +31 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-details-section.js +43 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/columns.js +44 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/filters.js +18 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/query.js +37 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/table.js +58 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/page.js +39 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/columns.js +58 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/filters.js +13 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/query.js +31 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/table.js +56 -0
- package/.medusa/server/src/admin/routes/store-credit-accounts/page.js +19 -0
- package/.medusa/server/src/admin/utils/date-utils.js +27 -0
- package/.medusa/server/src/admin/utils/format-amount.js +9 -0
- package/.medusa/server/src/admin/utils/format-date.js +21 -0
- package/.medusa/server/src/admin/utils/refs.js +20 -0
- package/.medusa/server/src/admin/utils/statuses.js +23 -0
- package/.medusa/server/src/admin/utils/validations.js +71 -0
- package/.medusa/server/src/admin/utils/variants.js +92 -0
- package/.medusa/server/src/admin/widgets/customer-gift-cards-widget.js +67 -0
- package/.medusa/server/src/admin/widgets/customer-store-credit-widget.js +42 -0
- package/.medusa/server/src/admin/widgets/order-gift-cards-widget.js +58 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/redeem/route.js +25 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/route.js +41 -0
- package/.medusa/server/src/api/admin/gift-cards/[id]/transfer/route.js +24 -0
- package/.medusa/server/src/api/admin/gift-cards/middlewares.js +55 -0
- package/.medusa/server/src/api/admin/gift-cards/query-config.js +29 -0
- package/.medusa/server/src/api/admin/gift-cards/route.js +42 -0
- package/.medusa/server/src/api/admin/gift-cards/validators.js +69 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/[id]/route.js +24 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/[id]/transactions/route.js +23 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/middlewares.js +38 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/query-config.js +43 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/route.js +52 -0
- package/.medusa/server/src/api/admin/store-credit-accounts/validators.js +51 -0
- package/.medusa/server/src/api/admin/transaction-groups/middlewares.js +16 -0
- package/.medusa/server/src/api/admin/transaction-groups/query-config.js +13 -0
- package/.medusa/server/src/api/admin/transaction-groups/route.js +27 -0
- package/.medusa/server/src/api/admin/transaction-groups/validators.js +19 -0
- package/.medusa/server/src/api/middlewares.js +22 -0
- package/.medusa/server/src/api/store/carts/[id]/gift-cards/route.js +43 -0
- package/.medusa/server/src/api/store/carts/middlewares.js +26 -0
- package/.medusa/server/src/api/store/carts/query-config.js +9 -0
- package/.medusa/server/src/api/store/carts/validators.js +15 -0
- package/.medusa/server/src/api/store/gift-card-invitations/[code]/accept/route.js +24 -0
- package/.medusa/server/src/api/store/gift-card-invitations/[code]/reject/route.js +24 -0
- package/.medusa/server/src/api/store/gift-card-invitations/middlewares.js +30 -0
- package/.medusa/server/src/api/store/gift-card-invitations/query-config.js +17 -0
- package/.medusa/server/src/api/store/gift-card-invitations/validators.js +14 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/invitation/route.js +26 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/redeem/route.js +24 -0
- package/.medusa/server/src/api/store/gift-cards/[id]/route.js +16 -0
- package/.medusa/server/src/api/store/gift-cards/middlewares.js +46 -0
- package/.medusa/server/src/api/store/gift-cards/query-config.js +26 -0
- package/.medusa/server/src/api/store/gift-cards/route.js +28 -0
- package/.medusa/server/src/api/store/gift-cards/validators.js +26 -0
- package/.medusa/server/src/api/store/store-credit-accounts/[id]/route.js +31 -0
- package/.medusa/server/src/api/store/store-credit-accounts/middlewares.js +28 -0
- package/.medusa/server/src/api/store/store-credit-accounts/query-config.js +24 -0
- package/.medusa/server/src/api/store/store-credit-accounts/route.js +40 -0
- package/.medusa/server/src/api/store/store-credit-accounts/validators.js +17 -0
- package/.medusa/server/src/links/cart-gift-cards-link.js +13 -0
- package/.medusa/server/src/links/customer-gift-card-link.js +13 -0
- package/.medusa/server/src/links/customer-store-credit-account-link.js +13 -0
- package/.medusa/server/src/links/order-gift-cards-link.js +13 -0
- package/.medusa/server/src/links/order-line-item-gift-card-link.js +19 -0
- package/.medusa/server/src/modules/loyalty/index.js +12 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250123130553.js +17 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250127174331.js +19 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141026.js +19 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206141429.js +14 -0
- package/.medusa/server/src/modules/loyalty/migrations/Migration20250206144714.js +14 -0
- package/.medusa/server/src/modules/loyalty/models/gift-card-invitation.js +20 -0
- package/.medusa/server/src/modules/loyalty/models/gift-card.js +28 -0
- package/.medusa/server/src/modules/loyalty/service.js +15 -0
- package/.medusa/server/src/modules/store-credit/index.js +12 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250129115518.js +16 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250130213237.js +18 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250130220640.js +19 -0
- package/.medusa/server/src/modules/store-credit/migrations/Migration20250131205753.js +14 -0
- package/.medusa/server/src/modules/store-credit/models/account-transaction.js +27 -0
- package/.medusa/server/src/modules/store-credit/models/store-credit-account.js +29 -0
- package/.medusa/server/src/modules/store-credit/models/transaction-group.js +28 -0
- package/.medusa/server/src/modules/store-credit/service.js +412 -0
- package/.medusa/server/src/providers/index.js +12 -0
- package/.medusa/server/src/providers/store-credit-payment/index.js +12 -0
- package/.medusa/server/src/providers/store-credit-payment/service.js +181 -0
- package/.medusa/server/src/subscribers/create-gift-card.js +94 -0
- package/.medusa/server/src/types/cart/index.js +3 -0
- package/.medusa/server/src/types/http/gift-card.js +3 -0
- package/.medusa/server/src/types/http/index.js +21 -0
- package/.medusa/server/src/types/http/store-credit-account.js +3 -0
- package/.medusa/server/src/types/http/transaction-group.js +3 -0
- package/.medusa/server/src/types/http/transaction.js +3 -0
- package/.medusa/server/src/types/index.js +21 -0
- package/.medusa/server/src/types/loyalty/index.js +20 -0
- package/.medusa/server/src/types/loyalty/module.js +17 -0
- package/.medusa/server/src/types/loyalty/service.js +3 -0
- package/.medusa/server/src/types/loyalty/workflows.js +3 -0
- package/.medusa/server/src/types/modules.js +14 -0
- package/.medusa/server/src/types/store-credit/index.js +19 -0
- package/.medusa/server/src/types/store-credit/module.js +10 -0
- package/.medusa/server/src/types/store-credit/service.js +3 -0
- package/.medusa/server/src/workflows/carts/workflows/add-gift-card-to-cart.js +167 -0
- package/.medusa/server/src/workflows/carts/workflows/confirm-cart-credit-lines.js +95 -0
- package/.medusa/server/src/workflows/carts/workflows/refresh-cart-gift-cards.js +136 -0
- package/.medusa/server/src/workflows/carts/workflows/remove-gift-cart-from-cart.js +66 -0
- package/.medusa/server/src/workflows/common/steps/validate-presence-of.js +11 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/create-gift-card-invitation.js +17 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/delete-gift-card-invitation.js +20 -0
- package/.medusa/server/src/workflows/gift-card-invitation/steps/update-gift-card-invitation.js +31 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/accept-gift-card-invitation.js +79 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/create-gift-card-invitation.js +66 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/delete-gift-card-invitation.js +10 -0
- package/.medusa/server/src/workflows/gift-card-invitation/workflows/reject-gift-card-invitation.js +70 -0
- package/.medusa/server/src/workflows/gift-cards/steps/create-gift-cards.js +17 -0
- package/.medusa/server/src/workflows/gift-cards/steps/delete-gift-cards.js +17 -0
- package/.medusa/server/src/workflows/gift-cards/steps/retrieve-gift-card-balance.js +20 -0
- package/.medusa/server/src/workflows/gift-cards/steps/update-gift-cards.js +34 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/create-gift-cards.js +12 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/delete-gift-card.js +19 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/redeem-gift-card.js +90 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/transfer-gift-card.js +48 -0
- package/.medusa/server/src/workflows/gift-cards/workflows/update-gift-cards.js +12 -0
- package/.medusa/server/src/workflows/hooks/after-order-created.js +31 -0
- package/.medusa/server/src/workflows/hooks/after-order-credit-lines-created.js +31 -0
- package/.medusa/server/src/workflows/hooks/before-payment-collection-refresh.js +26 -0
- package/.medusa/server/src/workflows/hooks/complete-cart-before-payment-authorization.js +27 -0
- package/.medusa/server/src/workflows/orders/workflows/link-gift-cards-to-order.js +58 -0
- package/.medusa/server/src/workflows/orders/workflows/refund-gift-card-credit-lines.js +96 -0
- package/.medusa/server/src/workflows/store-credit/steps/create-store-credit-accounts.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/create-transaction-groups.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/credit-account.js +17 -0
- package/.medusa/server/src/workflows/store-credit/steps/debit-account.js +17 -0
- package/.medusa/server/src/workflows/store-credit/workflows/create-store-credit-accounts.js +57 -0
- package/.medusa/server/src/workflows/store-credit/workflows/create-transaction-groups.js +12 -0
- package/.medusa/server/src/workflows/store-credit/workflows/credit-accounts.js +12 -0
- package/.medusa/server/src/workflows/store-credit/workflows/debit-accounts.js +12 -0
- package/.medusa/server/types/loyalty/module.js +8 -0
- package/README.md +62 -0
- package/package.json +94 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import get from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/lodash/get.js";
|
|
2
|
+
import set from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/lodash/set.js";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
const useDataGridFormHandlers = ({
|
|
5
|
+
matrix,
|
|
6
|
+
form,
|
|
7
|
+
anchor
|
|
8
|
+
}) => {
|
|
9
|
+
const { getValues, reset } = form;
|
|
10
|
+
const getSelectionValues = useCallback(
|
|
11
|
+
(fields) => {
|
|
12
|
+
if (!fields.length) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const allValues = getValues();
|
|
16
|
+
return fields.map((field) => {
|
|
17
|
+
return field.split(".").reduce((obj, key) => obj == null ? void 0 : obj[key], allValues);
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
[getValues]
|
|
21
|
+
);
|
|
22
|
+
const setSelectionValues = useCallback(
|
|
23
|
+
async (fields, values, isHistory) => {
|
|
24
|
+
if (!fields.length || !anchor) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const type = matrix.getCellType(anchor);
|
|
28
|
+
if (!type) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const convertedValues = convertArrayToPrimitive(values, type);
|
|
32
|
+
const currentValues = getValues();
|
|
33
|
+
fields.forEach((field, index) => {
|
|
34
|
+
if (!field) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const valueIndex = index % values.length;
|
|
38
|
+
const newValue = convertedValues[valueIndex];
|
|
39
|
+
setValue(currentValues, field, newValue, type, isHistory);
|
|
40
|
+
});
|
|
41
|
+
reset(currentValues, {
|
|
42
|
+
keepDirty: true,
|
|
43
|
+
keepTouched: true,
|
|
44
|
+
keepDefaultValues: true
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
[matrix, anchor, getValues, reset]
|
|
48
|
+
);
|
|
49
|
+
return {
|
|
50
|
+
getSelectionValues,
|
|
51
|
+
setSelectionValues
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
function convertToNumber(value) {
|
|
55
|
+
if (typeof value === "number") {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
const converted = Number(value);
|
|
59
|
+
if (isNaN(converted)) {
|
|
60
|
+
throw new Error(`String "${value}" cannot be converted to number.`);
|
|
61
|
+
}
|
|
62
|
+
return converted;
|
|
63
|
+
}
|
|
64
|
+
function convertToBoolean(value) {
|
|
65
|
+
if (typeof value === "boolean") {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
if (typeof value === "undefined" || value === null) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const lowerValue = value.toLowerCase();
|
|
72
|
+
if (lowerValue === "true" || lowerValue === "false") {
|
|
73
|
+
return lowerValue === "true";
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`String "${value}" cannot be converted to boolean.`);
|
|
76
|
+
}
|
|
77
|
+
function covertToString(value) {
|
|
78
|
+
if (typeof value === "undefined" || value === null) {
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
return String(value);
|
|
82
|
+
}
|
|
83
|
+
function convertToggleableNumber(value) {
|
|
84
|
+
let obj = value;
|
|
85
|
+
if (typeof obj === "string") {
|
|
86
|
+
try {
|
|
87
|
+
obj = JSON.parse(obj);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new Error(`String "${value}" cannot be converted to object.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return obj;
|
|
93
|
+
}
|
|
94
|
+
function setValue(currentValues, field, newValue, type, isHistory) {
|
|
95
|
+
if (type !== "togglable-number") {
|
|
96
|
+
set(currentValues, field, newValue);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
setValueToggleableNumber(currentValues, field, newValue, isHistory);
|
|
100
|
+
}
|
|
101
|
+
function setValueToggleableNumber(currentValues, field, newValue, isHistory) {
|
|
102
|
+
const currentValue = get(currentValues, field);
|
|
103
|
+
const { disabledToggle } = currentValue;
|
|
104
|
+
const normalizeQuantity = (value) => {
|
|
105
|
+
if (disabledToggle && value === "") {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
};
|
|
110
|
+
const determineChecked = (quantity2) => {
|
|
111
|
+
if (disabledToggle) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return quantity2 !== "" && quantity2 != null;
|
|
115
|
+
};
|
|
116
|
+
const quantity = normalizeQuantity(newValue.quantity);
|
|
117
|
+
const checked = isHistory ? disabledToggle ? true : newValue.checked : determineChecked(quantity);
|
|
118
|
+
set(currentValues, field, {
|
|
119
|
+
...currentValue,
|
|
120
|
+
quantity,
|
|
121
|
+
checked
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function convertArrayToPrimitive(values, type) {
|
|
125
|
+
switch (type) {
|
|
126
|
+
case "number":
|
|
127
|
+
return values.map((v) => {
|
|
128
|
+
if (v === "") {
|
|
129
|
+
return v;
|
|
130
|
+
}
|
|
131
|
+
if (v == null) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
return convertToNumber(v);
|
|
135
|
+
});
|
|
136
|
+
case "togglable-number":
|
|
137
|
+
return values.map(convertToggleableNumber);
|
|
138
|
+
case "boolean":
|
|
139
|
+
return values.map(convertToBoolean);
|
|
140
|
+
case "text":
|
|
141
|
+
return values.map(covertToString);
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unsupported target type "${type}".`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
convertArrayToPrimitive,
|
|
148
|
+
useDataGridFormHandlers
|
|
149
|
+
};
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { DataGridBulkUpdateCommand } from "../models/data-grid-bulk-update-command.js";
|
|
3
|
+
import { DataGridUpdateCommand } from "../models/data-grid-update-command.js";
|
|
4
|
+
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
5
|
+
const VERTICAL_KEYS = ["ArrowUp", "ArrowDown"];
|
|
6
|
+
const useDataGridKeydownEvent = ({
|
|
7
|
+
containerRef,
|
|
8
|
+
matrix,
|
|
9
|
+
anchor,
|
|
10
|
+
rangeEnd,
|
|
11
|
+
isEditing,
|
|
12
|
+
setTrapActive,
|
|
13
|
+
scrollToCoordinates,
|
|
14
|
+
setSingleRange,
|
|
15
|
+
setRangeEnd,
|
|
16
|
+
onEditingChangeHandler,
|
|
17
|
+
getValues,
|
|
18
|
+
setValue,
|
|
19
|
+
execute,
|
|
20
|
+
undo,
|
|
21
|
+
redo,
|
|
22
|
+
queryTool,
|
|
23
|
+
getSelectionValues,
|
|
24
|
+
setSelectionValues,
|
|
25
|
+
restoreSnapshot,
|
|
26
|
+
createSnapshot
|
|
27
|
+
}) => {
|
|
28
|
+
const handleKeyboardNavigation = useCallback(
|
|
29
|
+
(e) => {
|
|
30
|
+
if (!anchor) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const type = matrix.getCellType(anchor);
|
|
34
|
+
if (isEditing && type !== "boolean") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const direction = VERTICAL_KEYS.includes(e.key) ? "vertical" : "horizontal";
|
|
38
|
+
const basis = direction === "horizontal" ? anchor : e.shiftKey ? rangeEnd : anchor;
|
|
39
|
+
const updater = direction === "horizontal" ? setSingleRange : e.shiftKey ? setRangeEnd : setSingleRange;
|
|
40
|
+
if (!basis) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const { row, col } = basis;
|
|
44
|
+
const handleNavigation = (coords) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
scrollToCoordinates(coords, direction);
|
|
48
|
+
updater(coords);
|
|
49
|
+
};
|
|
50
|
+
const next = matrix.getValidMovement(
|
|
51
|
+
row,
|
|
52
|
+
col,
|
|
53
|
+
e.key,
|
|
54
|
+
e.metaKey || e.ctrlKey
|
|
55
|
+
);
|
|
56
|
+
handleNavigation(next);
|
|
57
|
+
},
|
|
58
|
+
[
|
|
59
|
+
isEditing,
|
|
60
|
+
anchor,
|
|
61
|
+
rangeEnd,
|
|
62
|
+
scrollToCoordinates,
|
|
63
|
+
setSingleRange,
|
|
64
|
+
setRangeEnd,
|
|
65
|
+
matrix
|
|
66
|
+
]
|
|
67
|
+
);
|
|
68
|
+
const handleTabKey = useCallback(
|
|
69
|
+
(e) => {
|
|
70
|
+
if (!anchor) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
const { row, col } = anchor;
|
|
76
|
+
const key = e.shiftKey ? "ArrowLeft" : "ArrowRight";
|
|
77
|
+
const direction = "horizontal";
|
|
78
|
+
const next = matrix.getValidMovement(
|
|
79
|
+
row,
|
|
80
|
+
col,
|
|
81
|
+
key,
|
|
82
|
+
e.metaKey || e.ctrlKey
|
|
83
|
+
);
|
|
84
|
+
scrollToCoordinates(next, direction);
|
|
85
|
+
setSingleRange(next);
|
|
86
|
+
},
|
|
87
|
+
[anchor, scrollToCoordinates, setSingleRange, matrix]
|
|
88
|
+
);
|
|
89
|
+
const handleUndo = useCallback(
|
|
90
|
+
(e) => {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
if (e.shiftKey) {
|
|
93
|
+
redo();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
undo();
|
|
97
|
+
},
|
|
98
|
+
[redo, undo]
|
|
99
|
+
);
|
|
100
|
+
const handleSpaceKeyBoolean = useCallback(
|
|
101
|
+
(anchor2) => {
|
|
102
|
+
const end = rangeEnd ?? anchor2;
|
|
103
|
+
const fields = matrix.getFieldsInSelection(anchor2, end);
|
|
104
|
+
const prev = getSelectionValues(fields);
|
|
105
|
+
const allChecked = prev.every((value) => value === true);
|
|
106
|
+
const next = Array.from({ length: prev.length }, () => !allChecked);
|
|
107
|
+
const command = new DataGridBulkUpdateCommand({
|
|
108
|
+
fields,
|
|
109
|
+
next,
|
|
110
|
+
prev,
|
|
111
|
+
setter: setSelectionValues
|
|
112
|
+
});
|
|
113
|
+
execute(command);
|
|
114
|
+
},
|
|
115
|
+
[rangeEnd, matrix, getSelectionValues, setSelectionValues, execute]
|
|
116
|
+
);
|
|
117
|
+
const handleSpaceKeyTextOrNumber = useCallback(
|
|
118
|
+
(anchor2) => {
|
|
119
|
+
const field = matrix.getCellField(anchor2);
|
|
120
|
+
const input = queryTool == null ? void 0 : queryTool.getInput(anchor2);
|
|
121
|
+
if (!field || !input) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
createSnapshot(anchor2);
|
|
125
|
+
const current = getValues(field);
|
|
126
|
+
const next = "";
|
|
127
|
+
const command = new DataGridUpdateCommand({
|
|
128
|
+
next,
|
|
129
|
+
prev: current,
|
|
130
|
+
setter: (value) => {
|
|
131
|
+
setValue(field, value, {
|
|
132
|
+
shouldDirty: true,
|
|
133
|
+
shouldTouch: true
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
execute(command);
|
|
138
|
+
input.focus();
|
|
139
|
+
},
|
|
140
|
+
[matrix, queryTool, getValues, execute, setValue, createSnapshot]
|
|
141
|
+
);
|
|
142
|
+
const handleSpaceKeyTogglableNumber = useCallback(
|
|
143
|
+
(anchor2) => {
|
|
144
|
+
const field = matrix.getCellField(anchor2);
|
|
145
|
+
const input = queryTool == null ? void 0 : queryTool.getInput(anchor2);
|
|
146
|
+
if (!field || !input) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
createSnapshot(anchor2);
|
|
150
|
+
const current = getValues(field);
|
|
151
|
+
let checked = current.checked;
|
|
152
|
+
if (!current.disabledToggle) {
|
|
153
|
+
checked = false;
|
|
154
|
+
}
|
|
155
|
+
const next = { ...current, quantity: "", checked };
|
|
156
|
+
const command = new DataGridUpdateCommand({
|
|
157
|
+
next,
|
|
158
|
+
prev: current,
|
|
159
|
+
setter: (value) => {
|
|
160
|
+
setValue(field, value, {
|
|
161
|
+
shouldDirty: true,
|
|
162
|
+
shouldTouch: true
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
execute(command);
|
|
167
|
+
input.focus();
|
|
168
|
+
},
|
|
169
|
+
[matrix, queryTool, getValues, execute, setValue, createSnapshot]
|
|
170
|
+
);
|
|
171
|
+
const handleSpaceKey = useCallback(
|
|
172
|
+
(e) => {
|
|
173
|
+
if (!anchor || isEditing) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
const type = matrix.getCellType(anchor);
|
|
178
|
+
if (!type) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
switch (type) {
|
|
182
|
+
case "boolean":
|
|
183
|
+
handleSpaceKeyBoolean(anchor);
|
|
184
|
+
break;
|
|
185
|
+
case "togglable-number":
|
|
186
|
+
handleSpaceKeyTogglableNumber(anchor);
|
|
187
|
+
break;
|
|
188
|
+
case "number":
|
|
189
|
+
case "text":
|
|
190
|
+
handleSpaceKeyTextOrNumber(anchor);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
[
|
|
195
|
+
anchor,
|
|
196
|
+
isEditing,
|
|
197
|
+
matrix,
|
|
198
|
+
handleSpaceKeyBoolean,
|
|
199
|
+
handleSpaceKeyTextOrNumber,
|
|
200
|
+
handleSpaceKeyTogglableNumber
|
|
201
|
+
]
|
|
202
|
+
);
|
|
203
|
+
const handleMoveOnEnter = useCallback(
|
|
204
|
+
(e, anchor2) => {
|
|
205
|
+
const direction = e.shiftKey ? "ArrowUp" : "ArrowDown";
|
|
206
|
+
const pos = matrix.getValidMovement(
|
|
207
|
+
anchor2.row,
|
|
208
|
+
anchor2.col,
|
|
209
|
+
direction,
|
|
210
|
+
false
|
|
211
|
+
);
|
|
212
|
+
if (anchor2.row !== pos.row || anchor2.col !== pos.col) {
|
|
213
|
+
setSingleRange(pos);
|
|
214
|
+
scrollToCoordinates(pos, "vertical");
|
|
215
|
+
} else {
|
|
216
|
+
const container = queryTool == null ? void 0 : queryTool.getContainer(anchor2);
|
|
217
|
+
container == null ? void 0 : container.focus();
|
|
218
|
+
}
|
|
219
|
+
onEditingChangeHandler(false);
|
|
220
|
+
},
|
|
221
|
+
[
|
|
222
|
+
queryTool,
|
|
223
|
+
matrix,
|
|
224
|
+
scrollToCoordinates,
|
|
225
|
+
setSingleRange,
|
|
226
|
+
onEditingChangeHandler
|
|
227
|
+
]
|
|
228
|
+
);
|
|
229
|
+
const handleEditOnEnter = useCallback(
|
|
230
|
+
(anchor2) => {
|
|
231
|
+
const input = queryTool == null ? void 0 : queryTool.getInput(anchor2);
|
|
232
|
+
if (!input) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
input.focus();
|
|
236
|
+
onEditingChangeHandler(true);
|
|
237
|
+
},
|
|
238
|
+
[queryTool, onEditingChangeHandler]
|
|
239
|
+
);
|
|
240
|
+
const handleEnterKeyTextOrNumber = useCallback(
|
|
241
|
+
(e, anchor2) => {
|
|
242
|
+
if (isEditing) {
|
|
243
|
+
handleMoveOnEnter(e, anchor2);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
handleEditOnEnter(anchor2);
|
|
247
|
+
},
|
|
248
|
+
[handleMoveOnEnter, handleEditOnEnter, isEditing]
|
|
249
|
+
);
|
|
250
|
+
const handleEnterKeyBoolean = useCallback(
|
|
251
|
+
(e, anchor2) => {
|
|
252
|
+
const field = matrix.getCellField(anchor2);
|
|
253
|
+
if (!field) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const current = getValues(field);
|
|
257
|
+
let next;
|
|
258
|
+
if (typeof current === "boolean") {
|
|
259
|
+
next = !current;
|
|
260
|
+
} else {
|
|
261
|
+
next = true;
|
|
262
|
+
}
|
|
263
|
+
const command = new DataGridUpdateCommand({
|
|
264
|
+
next,
|
|
265
|
+
prev: current,
|
|
266
|
+
setter: (value) => {
|
|
267
|
+
setValue(field, value, {
|
|
268
|
+
shouldDirty: true,
|
|
269
|
+
shouldTouch: true
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
execute(command);
|
|
274
|
+
handleMoveOnEnter(e, anchor2);
|
|
275
|
+
},
|
|
276
|
+
[execute, getValues, handleMoveOnEnter, matrix, setValue]
|
|
277
|
+
);
|
|
278
|
+
const handleEnterKey = useCallback(
|
|
279
|
+
(e) => {
|
|
280
|
+
if (!anchor) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
e.preventDefault();
|
|
284
|
+
const type = matrix.getCellType(anchor);
|
|
285
|
+
switch (type) {
|
|
286
|
+
case "togglable-number":
|
|
287
|
+
case "text":
|
|
288
|
+
case "number":
|
|
289
|
+
handleEnterKeyTextOrNumber(e, anchor);
|
|
290
|
+
break;
|
|
291
|
+
case "boolean": {
|
|
292
|
+
handleEnterKeyBoolean(e, anchor);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
[anchor, matrix, handleEnterKeyTextOrNumber, handleEnterKeyBoolean]
|
|
298
|
+
);
|
|
299
|
+
const handleDeleteKeyTogglableNumber = useCallback(
|
|
300
|
+
(anchor2, rangeEnd2) => {
|
|
301
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
302
|
+
const prev = getSelectionValues(fields);
|
|
303
|
+
const next = prev.map((value) => ({
|
|
304
|
+
...value,
|
|
305
|
+
quantity: "",
|
|
306
|
+
checked: value.disableToggle ? value.checked : false
|
|
307
|
+
}));
|
|
308
|
+
const command = new DataGridBulkUpdateCommand({
|
|
309
|
+
fields,
|
|
310
|
+
next,
|
|
311
|
+
prev,
|
|
312
|
+
setter: setSelectionValues
|
|
313
|
+
});
|
|
314
|
+
execute(command);
|
|
315
|
+
},
|
|
316
|
+
[matrix, getSelectionValues, setSelectionValues, execute]
|
|
317
|
+
);
|
|
318
|
+
const handleDeleteKeyTextOrNumber = useCallback(
|
|
319
|
+
(anchor2, rangeEnd2) => {
|
|
320
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
321
|
+
const prev = getSelectionValues(fields);
|
|
322
|
+
const next = Array.from({ length: prev.length }, () => "");
|
|
323
|
+
const command = new DataGridBulkUpdateCommand({
|
|
324
|
+
fields,
|
|
325
|
+
next,
|
|
326
|
+
prev,
|
|
327
|
+
setter: setSelectionValues
|
|
328
|
+
});
|
|
329
|
+
execute(command);
|
|
330
|
+
},
|
|
331
|
+
[matrix, getSelectionValues, setSelectionValues, execute]
|
|
332
|
+
);
|
|
333
|
+
const handleDeleteKeyBoolean = useCallback(
|
|
334
|
+
(anchor2, rangeEnd2) => {
|
|
335
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
336
|
+
const prev = getSelectionValues(fields);
|
|
337
|
+
const next = Array.from({ length: prev.length }, () => false);
|
|
338
|
+
const command = new DataGridBulkUpdateCommand({
|
|
339
|
+
fields,
|
|
340
|
+
next,
|
|
341
|
+
prev,
|
|
342
|
+
setter: setSelectionValues
|
|
343
|
+
});
|
|
344
|
+
execute(command);
|
|
345
|
+
},
|
|
346
|
+
[execute, getSelectionValues, matrix, setSelectionValues]
|
|
347
|
+
);
|
|
348
|
+
const handleDeleteKey = useCallback(
|
|
349
|
+
(e) => {
|
|
350
|
+
if (!anchor || !rangeEnd || isEditing) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
const type = matrix.getCellType(anchor);
|
|
355
|
+
if (!type) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
switch (type) {
|
|
359
|
+
case "text":
|
|
360
|
+
case "number":
|
|
361
|
+
handleDeleteKeyTextOrNumber(anchor, rangeEnd);
|
|
362
|
+
break;
|
|
363
|
+
case "boolean":
|
|
364
|
+
handleDeleteKeyBoolean(anchor, rangeEnd);
|
|
365
|
+
break;
|
|
366
|
+
case "togglable-number":
|
|
367
|
+
handleDeleteKeyTogglableNumber(anchor, rangeEnd);
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
[
|
|
372
|
+
anchor,
|
|
373
|
+
rangeEnd,
|
|
374
|
+
isEditing,
|
|
375
|
+
matrix,
|
|
376
|
+
handleDeleteKeyTextOrNumber,
|
|
377
|
+
handleDeleteKeyBoolean,
|
|
378
|
+
handleDeleteKeyTogglableNumber
|
|
379
|
+
]
|
|
380
|
+
);
|
|
381
|
+
const handleEscapeKey = useCallback(
|
|
382
|
+
(e) => {
|
|
383
|
+
if (!anchor || !isEditing) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
e.preventDefault();
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
restoreSnapshot();
|
|
389
|
+
const container = queryTool == null ? void 0 : queryTool.getContainer(anchor);
|
|
390
|
+
container == null ? void 0 : container.focus();
|
|
391
|
+
},
|
|
392
|
+
[queryTool, isEditing, anchor, restoreSnapshot]
|
|
393
|
+
);
|
|
394
|
+
const handleSpecialFocusKeys = useCallback(
|
|
395
|
+
(e) => {
|
|
396
|
+
if (!containerRef || isEditing) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const focusableElements = getFocusableElements(containerRef);
|
|
400
|
+
const focusElement = (element) => {
|
|
401
|
+
if (element) {
|
|
402
|
+
setTrapActive(false);
|
|
403
|
+
element.focus();
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
switch (e.key) {
|
|
407
|
+
case ".":
|
|
408
|
+
focusElement(focusableElements.cancel);
|
|
409
|
+
break;
|
|
410
|
+
case ",":
|
|
411
|
+
focusElement(focusableElements.shortcuts);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
[isEditing, setTrapActive, containerRef]
|
|
416
|
+
);
|
|
417
|
+
const handleKeyDownEvent = useCallback(
|
|
418
|
+
(e) => {
|
|
419
|
+
if (ARROW_KEYS.includes(e.key)) {
|
|
420
|
+
handleKeyboardNavigation(e);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (e.key === "z" && (e.metaKey || e.ctrlKey)) {
|
|
424
|
+
handleUndo(e);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (e.key === " ") {
|
|
428
|
+
handleSpaceKey(e);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
432
|
+
handleDeleteKey(e);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (e.key === "Enter") {
|
|
436
|
+
handleEnterKey(e);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (e.key === "Escape") {
|
|
440
|
+
handleEscapeKey(e);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (e.key === "Tab") {
|
|
444
|
+
handleTabKey(e);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
[
|
|
449
|
+
handleEscapeKey,
|
|
450
|
+
handleKeyboardNavigation,
|
|
451
|
+
handleUndo,
|
|
452
|
+
handleSpaceKey,
|
|
453
|
+
handleEnterKey,
|
|
454
|
+
handleDeleteKey,
|
|
455
|
+
handleTabKey
|
|
456
|
+
]
|
|
457
|
+
);
|
|
458
|
+
return {
|
|
459
|
+
handleKeyDownEvent,
|
|
460
|
+
handleSpecialFocusKeys
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
function getFocusableElements(ref) {
|
|
464
|
+
const focusableElements = Array.from(
|
|
465
|
+
document.querySelectorAll(
|
|
466
|
+
"[tabindex], a, button, input, select, textarea"
|
|
467
|
+
)
|
|
468
|
+
);
|
|
469
|
+
const currentElementIndex = focusableElements.indexOf(ref.current);
|
|
470
|
+
const shortcuts = currentElementIndex > 0 ? focusableElements[currentElementIndex - 1] : null;
|
|
471
|
+
let cancel = null;
|
|
472
|
+
for (let i = currentElementIndex + 1; i < focusableElements.length; i++) {
|
|
473
|
+
if (!ref.current.contains(focusableElements[i])) {
|
|
474
|
+
cancel = focusableElements[i];
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return { shortcuts, cancel };
|
|
479
|
+
}
|
|
480
|
+
export {
|
|
481
|
+
useDataGridKeydownEvent
|
|
482
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { DataGridBulkUpdateCommand } from "../models/data-grid-bulk-update-command.js";
|
|
3
|
+
const useDataGridMouseUpEvent = ({
|
|
4
|
+
matrix,
|
|
5
|
+
anchor,
|
|
6
|
+
dragEnd,
|
|
7
|
+
setDragEnd,
|
|
8
|
+
isDragging,
|
|
9
|
+
setIsDragging,
|
|
10
|
+
setRangeEnd,
|
|
11
|
+
setIsSelecting,
|
|
12
|
+
getSelectionValues,
|
|
13
|
+
setSelectionValues,
|
|
14
|
+
execute
|
|
15
|
+
}) => {
|
|
16
|
+
const handleDragEnd = useCallback(() => {
|
|
17
|
+
if (!isDragging) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!anchor || !dragEnd) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const dragSelection = matrix.getFieldsInSelection(anchor, dragEnd);
|
|
24
|
+
const anchorField = matrix.getCellField(anchor);
|
|
25
|
+
if (!anchorField || !dragSelection.length) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const anchorValue = getSelectionValues([anchorField]);
|
|
29
|
+
const fields = dragSelection.filter((field) => field !== anchorField);
|
|
30
|
+
const prev = getSelectionValues(fields);
|
|
31
|
+
const next = Array.from({ length: prev.length }, () => anchorValue[0]);
|
|
32
|
+
const command = new DataGridBulkUpdateCommand({
|
|
33
|
+
fields,
|
|
34
|
+
prev,
|
|
35
|
+
next,
|
|
36
|
+
setter: setSelectionValues
|
|
37
|
+
});
|
|
38
|
+
execute(command);
|
|
39
|
+
setIsDragging(false);
|
|
40
|
+
setDragEnd(null);
|
|
41
|
+
setRangeEnd(dragEnd);
|
|
42
|
+
}, [
|
|
43
|
+
isDragging,
|
|
44
|
+
anchor,
|
|
45
|
+
dragEnd,
|
|
46
|
+
matrix,
|
|
47
|
+
getSelectionValues,
|
|
48
|
+
setSelectionValues,
|
|
49
|
+
execute,
|
|
50
|
+
setIsDragging,
|
|
51
|
+
setDragEnd,
|
|
52
|
+
setRangeEnd
|
|
53
|
+
]);
|
|
54
|
+
const handleMouseUpEvent = useCallback(() => {
|
|
55
|
+
handleDragEnd();
|
|
56
|
+
setIsSelecting(false);
|
|
57
|
+
}, [handleDragEnd, setIsSelecting]);
|
|
58
|
+
return {
|
|
59
|
+
handleMouseUpEvent
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
useDataGridMouseUpEvent
|
|
64
|
+
};
|