MockProcessor-498b60c5.js
1 year ago
MockProcessor-498b60c5.js.map
1 year ago
add-query-args-0e2a8393.js
1 year ago
add-query-args-0e2a8393.js.map
1 year ago
address-b892540d.js
1 year ago
address-b892540d.js.map
1 year ago
animation-registry-12eed2e3.js
1 year ago
animation-registry-12eed2e3.js.map
1 year ago
app-globals-707edcd4.js
1 year ago
app-globals-707edcd4.js.map
1 year ago
consumer-e06b16d3.js
1 year ago
consumer-e06b16d3.js.map
1 year ago
countries-c2f41f03.js
1 year ago
countries-c2f41f03.js.map
1 year ago
currency-a0c9bff4.js
1 year ago
currency-a0c9bff4.js.map
1 year ago
error-ca32663d.js
1 year ago
error-ca32663d.js.map
1 year ago
fetch-2032d11d.js
1 year ago
fetch-2032d11d.js.map
1 year ago
form-data-76641f16.js
1 year ago
form-data-76641f16.js.map
1 year ago
functions-2a4a4ba3.js
1 year ago
functions-2a4a4ba3.js.map
1 year ago
getters-929aa1df.js
1 year ago
getters-929aa1df.js.map
1 year ago
getters-a7eec27c.js
1 year ago
getters-a7eec27c.js.map
1 year ago
getters-b1d93841.js
1 year ago
getters-b1d93841.js.map
1 year ago
getters-e4172581.js
1 year ago
getters-e4172581.js.map
1 year ago
getters-ff7a502e.js
1 year ago
getters-ff7a502e.js.map
1 year ago
google-a86aa761.js
1 year ago
google-a86aa761.js.map
1 year ago
google-dd89f242.js
1 year ago
google-dd89f242.js.map
1 year ago
index-0202319f.js
1 year ago
index-0202319f.js.map
1 year ago
index-06061d4e.js
1 year ago
index-06061d4e.js.map
1 year ago
index-745b6bec.js
1 year ago
index-745b6bec.js.map
1 year ago
index-871d88b8.js
1 year ago
index-871d88b8.js.map
1 year ago
index-96490395.js
1 year ago
index-96490395.js.map
1 year ago
index-c5a96d53.js
2 years ago
index-c5a96d53.js.map
2 years ago
index.js
1 year ago
index.js.map
1 year ago
inline-c012a0f9.js
1 year ago
inline-c012a0f9.js.map
1 year ago
lazy-deb42890.js
1 year ago
lazy-deb42890.js.map
1 year ago
library-e110eea6.js
1 year ago
library-e110eea6.js.map
1 year ago
loader.js
1 year ago
loader.js.map
1 year ago
media-d21119a3.js
1 year ago
media-d21119a3.js.map
1 year ago
mutations-01792dfb.js
1 year ago
mutations-01792dfb.js.map
1 year ago
mutations-30225b1b.js
1 year ago
mutations-30225b1b.js.map
1 year ago
mutations-d5e8faea.js
1 year ago
mutations-d5e8faea.js.map
1 year ago
mutations-ed6d0770.js
1 year ago
mutations-ed6d0770.js.map
1 year ago
page-align-0cdacf32.js
1 year ago
page-align-0cdacf32.js.map
1 year ago
price-d5770168.js
1 year ago
price-d5770168.js.map
1 year ago
pure-963214cb.js
1 year ago
pure-963214cb.js.map
1 year ago
quantity-1f39f750.js
1 year ago
quantity-1f39f750.js.map
1 year ago
remove-query-args-938c53ea.js
1 year ago
remove-query-args-938c53ea.js.map
1 year ago
sc-address_3.entry.js
1 year ago
sc-address_3.entry.js.map
1 year ago
sc-alert_13.entry.js
1 year ago
sc-alert_13.entry.js.map
1 year ago
sc-avatar.entry.js
1 year ago
sc-avatar.entry.js.map
1 year ago
sc-badge-notice.entry.js
1 year ago
sc-badge-notice.entry.js.map
1 year ago
sc-breadcrumb.entry.js
1 year ago
sc-breadcrumb.entry.js.map
1 year ago
sc-breadcrumbs.entry.js
1 year ago
sc-breadcrumbs.entry.js.map
1 year ago
sc-button-group.entry.js
1 year ago
sc-button-group.entry.js.map
1 year ago
sc-cancel-dialog_2.entry.js
1 year ago
sc-cancel-dialog_2.entry.js.map
1 year ago
sc-cancel-discount_4.entry.js
1 year ago
sc-cancel-discount_4.entry.js.map
1 year ago
sc-card.entry.js
1 year ago
sc-card.entry.js.map
1 year ago
sc-cart-button.entry.js
1 year ago
sc-cart-button.entry.js.map
1 year ago
sc-cart-form-submit.entry.js
1 year ago
sc-cart-form-submit.entry.js.map
1 year ago
sc-cart-form.entry.js
1 year ago
sc-cart-form.entry.js.map
1 year ago
sc-cart-header.entry.js
1 year ago
sc-cart-header.entry.js.map
1 year ago
sc-cart-icon.entry.js
1 year ago
sc-cart-icon.entry.js.map
1 year ago
sc-cart-loader.entry.js
1 year ago
sc-cart-loader.entry.js.map
1 year ago
sc-cart-session-provider_3.entry.js
1 year ago
sc-cart-session-provider_3.entry.js.map
1 year ago
sc-cart-submit.entry.js
1 year ago
sc-cart-submit.entry.js.map
1 year ago
sc-cart.entry.js
1 year ago
sc-cart.entry.js.map
1 year ago
sc-cc-logo_2.entry.js
1 year ago
sc-cc-logo_2.entry.js.map
1 year ago
sc-charges-list.entry.js
1 year ago
sc-charges-list.entry.js.map
1 year ago
sc-checkout-form-errors.entry.js
1 year ago
sc-checkout-form-errors.entry.js.map
1 year ago
sc-checkout-mollie-payment_2.entry.js
1 year ago
sc-checkout-mollie-payment_2.entry.js.map
1 year ago
sc-checkout-product-price-variant-selector.entry.js
1 year ago
sc-checkout-product-price-variant-selector.entry.js.map
1 year ago
sc-checkout-stock-alert_9.entry.js
1 year ago
sc-checkout-stock-alert_9.entry.js.map
1 year ago
sc-checkout.entry.js
1 year ago
sc-checkout.entry.js.map
1 year ago
sc-choice-container.entry.js
1 year ago
sc-choice-container.entry.js.map
1 year ago
sc-choice.entry.js
1 year ago
sc-choice.entry.js.map
1 year ago
sc-choices.entry.js
1 year ago
sc-choices.entry.js.map
1 year ago
sc-column_2.entry.js
1 year ago
sc-column_2.entry.js.map
1 year ago
sc-compact-address_16.entry.js
1 year ago
sc-compact-address_16.entry.js.map
1 year ago
sc-conditional-form.entry.js
1 year ago
sc-conditional-form.entry.js.map
1 year ago
sc-consumer.entry.js
1 year ago
sc-consumer.entry.js.map
1 year ago
sc-coupon-form.entry.js
1 year ago
sc-coupon-form.entry.js.map
1 year ago
sc-custom-order-price-input.entry.js
1 year ago
sc-custom-order-price-input.entry.js.map
1 year ago
sc-customer-details.entry.js
1 year ago
sc-customer-details.entry.js.map
1 year ago
sc-customer-edit.entry.js
1 year ago
sc-customer-edit.entry.js.map
1 year ago
sc-customer-email.entry.js
1 year ago
sc-customer-email.entry.js.map
1 year ago
sc-customer-firstname.entry.js
1 year ago
sc-customer-firstname.entry.js.map
1 year ago
sc-customer-lastname.entry.js
1 year ago
sc-customer-lastname.entry.js.map
1 year ago
sc-customer-name.entry.js
1 year ago
sc-customer-name.entry.js.map
1 year ago
sc-customer-phone.entry.js
1 year ago
sc-customer-phone.entry.js.map
1 year ago
sc-dashboard-customer-details.entry.js
1 year ago
sc-dashboard-customer-details.entry.js.map
1 year ago
sc-dashboard-downloads-list.entry.js
1 year ago
sc-dashboard-downloads-list.entry.js.map
1 year ago
sc-divider.entry.js
1 year ago
sc-divider.entry.js.map
1 year ago
sc-donation-choices.entry.js
1 year ago
sc-donation-choices.entry.js.map
1 year ago
sc-downloads-list.entry.js
1 year ago
sc-downloads-list.entry.js.map
1 year ago
sc-dropdown_3.entry.js
1 year ago
sc-dropdown_3.entry.js.map
1 year ago
sc-empty.entry.js
1 year ago
sc-empty.entry.js.map
1 year ago
sc-express-payment.entry.js
1 year ago
sc-express-payment.entry.js.map
1 year ago
sc-feature-demo-banner.entry.js
1 year ago
sc-feature-demo-banner.entry.js.map
1 year ago
sc-form-control_2.entry.js
1 year ago
sc-form-control_2.entry.js.map
1 year ago
sc-form-row.entry.js
1 year ago
sc-form-row.entry.js.map
1 year ago
sc-form.entry.js
1 year ago
sc-form.entry.js.map
1 year ago
sc-format-bytes.entry.js
1 year ago
sc-format-bytes.entry.js.map
1 year ago
sc-format-interval.entry.js
1 year ago
sc-format-interval.entry.js.map
1 year ago
sc-fulfillment-shipping-status-badge.entry.js
1 year ago
sc-fulfillment-shipping-status-badge.entry.js.map
1 year ago
sc-fulfillments.entry.js
1 year ago
sc-fulfillments.entry.js.map
1 year ago
sc-heading_2.entry.js
1 year ago
sc-heading_2.entry.js.map
1 year ago
sc-image-slider.entry.js
1 year ago
sc-image-slider.entry.js.map
1 year ago
sc-invoice-status-badge.entry.js
1 year ago
sc-invoice-status-badge.entry.js.map
1 year ago
sc-invoices-list.entry.js
1 year ago
sc-invoices-list.entry.js.map
1 year ago
sc-license.entry.js
1 year ago
sc-license.entry.js.map
1 year ago
sc-licenses-list.entry.js
1 year ago
sc-licenses-list.entry.js.map
1 year ago
sc-line-item-bump.entry.js
1 year ago
sc-line-item-bump.entry.js.map
1 year ago
sc-line-item-total.entry.js
1 year ago
sc-line-item-total.entry.js.map
1 year ago
sc-line-item.entry.js
1 year ago
sc-line-item.entry.js.map
1 year ago
sc-line-items-provider.entry.js
1 year ago
sc-line-items-provider.entry.js.map
1 year ago
sc-line-items.entry.js
1 year ago
sc-line-items.entry.js.map
1 year ago
sc-login-form.entry.js
1 year ago
sc-login-form.entry.js.map
1 year ago
sc-manual-payment-method_3.entry.js
1 year ago
sc-manual-payment-method_3.entry.js.map
1 year ago
sc-menu-divider.entry.js
1 year ago
sc-menu-divider.entry.js.map
1 year ago
sc-menu-label_2.entry.js
1 year ago
sc-menu-label_2.entry.js.map
1 year ago
sc-mollie-add-method.entry.js
1 year ago
sc-mollie-add-method.entry.js.map
1 year ago
sc-order-confirmation-customer.entry.js
1 year ago
sc-order-confirmation-customer.entry.js.map
1 year ago
sc-order-confirmation-details.entry.js
1 year ago
sc-order-confirmation-details.entry.js.map
1 year ago
sc-order-confirmation-line-items_2.entry.js
1 year ago
sc-order-confirmation-line-items_2.entry.js.map
1 year ago
sc-order-confirmation.entry.js
1 year ago
sc-order-confirmation.entry.js.map
1 year ago
sc-order-coupon-form.entry.js
1 year ago
sc-order-coupon-form.entry.js.map
1 year ago
sc-order-detail.entry.js
1 year ago
sc-order-detail.entry.js.map
1 year ago
sc-order-fulfillment-badge.entry.js
1 year ago
sc-order-fulfillment-badge.entry.js.map
1 year ago
sc-order-manual-instructions.entry.js
1 year ago
sc-order-manual-instructions.entry.js.map
1 year ago
sc-order-password.entry.js
1 year ago
sc-order-password.entry.js.map
1 year ago
sc-order-return-badge.entry.js
1 year ago
sc-order-return-badge.entry.js.map
1 year ago
sc-order-shipment-badge.entry.js
1 year ago
sc-order-shipment-badge.entry.js.map
1 year ago
sc-order-status-badge.entry.js
1 year ago
sc-order-status-badge.entry.js.map
1 year ago
sc-order-submit.entry.js
1 year ago
sc-order-submit.entry.js.map
1 year ago
sc-order-summary.entry.js
1 year ago
sc-order-summary.entry.js.map
1 year ago
sc-order.entry.js
1 year ago
sc-order.entry.js.map
1 year ago
sc-orders-list.entry.js
1 year ago
sc-orders-list.entry.js.map
1 year ago
sc-pagination.entry.js
1 year ago
sc-pagination.entry.js.map
1 year ago
sc-password-nag.entry.js
1 year ago
sc-password-nag.entry.js.map
1 year ago
sc-password.entry.js
1 year ago
sc-password.entry.js.map
1 year ago
sc-payment-method-choice_2.entry.js
1 year ago
sc-payment-method-choice_2.entry.js.map
1 year ago
sc-payment-method-details.entry.js
1 year ago
sc-payment-method-details.entry.js.map
1 year ago
sc-payment-methods-list.entry.js
1 year ago
sc-payment-methods-list.entry.js.map
1 year ago
sc-payment.entry.js
1 year ago
sc-payment.entry.js.map
1 year ago
sc-paypal-add-method.entry.js
1 year ago
sc-paypal-add-method.entry.js.map
1 year ago
sc-paypal-buttons_2.entry.js
1 year ago
sc-paypal-buttons_2.entry.js.map
1 year ago
sc-paystack-add-method.entry.js
1 year ago
sc-paystack-add-method.entry.js.map
1 year ago
sc-phone-input.entry.js
1 year ago
sc-phone-input.entry.js.map
1 year ago
sc-pill-option.entry.js
1 year ago
sc-pill-option.entry.js.map
1 year ago
sc-premium-tag.entry.js
1 year ago
sc-premium-tag.entry.js.map
1 year ago
sc-price-choice-container.entry.js
1 year ago
sc-price-choice-container.entry.js.map
1 year ago
sc-price-choice.entry.js
1 year ago
sc-price-choice.entry.js.map
1 year ago
sc-price-choices.entry.js
1 year ago
sc-price-choices.entry.js.map
1 year ago
sc-price-input.entry.js
1 year ago
sc-price-input.entry.js.map
1 year ago
sc-price-range.entry.js
1 year ago
sc-price-range.entry.js.map
1 year ago
sc-price.entry.js
1 year ago
sc-price.entry.js.map
1 year ago
sc-product-buy-button.entry.js
1 year ago
sc-product-buy-button.entry.js.map
1 year ago
sc-product-donation-amount-choice.entry.js
1 year ago
sc-product-donation-amount-choice.entry.js.map
1 year ago
sc-product-donation-choices.entry.js
1 year ago
sc-product-donation-choices.entry.js.map
1 year ago
sc-product-donation-custom-amount.entry.js
1 year ago
sc-product-donation-custom-amount.entry.js.map
1 year ago
sc-product-item-image_3.entry.js
1 year ago
sc-product-item-image_3.entry.js.map
1 year ago
sc-product-item-list.entry.js
1 year ago
sc-product-item-list.entry.js.map
1 year ago
sc-product-item.entry.js
1 year ago
sc-product-item.entry.js.map
1 year ago
sc-product-line-item_2.entry.js
1 year ago
sc-product-line-item_2.entry.js.map
1 year ago
sc-product-pills-variant-option.entry.js
1 year ago
sc-product-pills-variant-option.entry.js.map
1 year ago
sc-product-price-choices.entry.js
1 year ago
sc-product-price-choices.entry.js.map
1 year ago
sc-product-price-modal.entry.js
1 year ago
sc-product-price-modal.entry.js.map
1 year ago
sc-product-price.entry.js
1 year ago
sc-product-price.entry.js.map
1 year ago
sc-product-quantity.entry.js
1 year ago
sc-product-quantity.entry.js.map
1 year ago
sc-product-selected-price.entry.js
1 year ago
sc-product-selected-price.entry.js.map
1 year ago
sc-product-text.entry.js
1 year ago
sc-product-text.entry.js.map
1 year ago
sc-provider.entry.js
1 year ago
sc-provider.entry.js.map
1 year ago
sc-provisional-banner.entry.js
1 year ago
sc-provisional-banner.entry.js.map
1 year ago
sc-purchase-downloads-list.entry.js
1 year ago
sc-purchase-downloads-list.entry.js.map
1 year ago
sc-recurring-price-choice-container.entry.js
1 year ago
sc-recurring-price-choice-container.entry.js.map
1 year ago
sc-rich-text.entry.js
1 year ago
sc-rich-text.entry.js.map
1 year ago
sc-spacing.entry.js
1 year ago
sc-spacing.entry.js.map
1 year ago
sc-stacked-list_2.entry.js
1 year ago
sc-stacked-list_2.entry.js.map
1 year ago
sc-stripe-add-method.entry.js
1 year ago
sc-stripe-add-method.entry.js.map
1 year ago
sc-stripe-element.entry.js
1 year ago
sc-stripe-element.entry.js.map
1 year ago
sc-stripe-payment-element.entry.js
1 year ago
sc-stripe-payment-element.entry.js.map
1 year ago
sc-stripe-payment-request.entry.js
1 year ago
sc-stripe-payment-request.entry.js.map
1 year ago
sc-subscription-ad-hoc-confirm.entry.js
1 year ago
sc-subscription-ad-hoc-confirm.entry.js.map
1 year ago
sc-subscription-details_2.entry.js
1 year ago
sc-subscription-details_2.entry.js.map
1 year ago
sc-subscription-payment-method.entry.js
1 year ago
sc-subscription-payment-method.entry.js.map
1 year ago
sc-subscription-payment.entry.js
1 year ago
sc-subscription-payment.entry.js.map
1 year ago
sc-subscription-switch.entry.js
1 year ago
sc-subscription-switch.entry.js.map
1 year ago
sc-subscription-variation-confirm.entry.js
1 year ago
sc-subscription-variation-confirm.entry.js.map
1 year ago
sc-subscription.entry.js
1 year ago
sc-subscription.entry.js.map
1 year ago
sc-subscriptions-list.entry.js
1 year ago
sc-subscriptions-list.entry.js.map
1 year ago
sc-summary.entry.js
1 year ago
sc-summary.entry.js.map
1 year ago
sc-switch.entry.js
1 year ago
sc-switch.entry.js.map
1 year ago
sc-tab-group.entry.js
1 year ago
sc-tab-group.entry.js.map
1 year ago
sc-tab-panel.entry.js
1 year ago
sc-tab-panel.entry.js.map
1 year ago
sc-tab.entry.js
1 year ago
sc-tab.entry.js.map
1 year ago
sc-table-head.entry.js
1 year ago
sc-table-head.entry.js.map
1 year ago
sc-table_3.entry.js
1 year ago
sc-table_3.entry.js.map
1 year ago
sc-tag.entry.js
1 year ago
sc-tag.entry.js.map
1 year ago
sc-toggle.entry.js
1 year ago
sc-toggle.entry.js.map
1 year ago
sc-toggles.entry.js
1 year ago
sc-toggles.entry.js.map
1 year ago
sc-total.entry.js
1 year ago
sc-total.entry.js.map
1 year ago
sc-upcoming-invoice.entry.js
1 year ago
sc-upcoming-invoice.entry.js.map
1 year ago
sc-upgrade-required.entry.js
1 year ago
sc-upgrade-required.entry.js.map
1 year ago
sc-upsell-countdown-timer.entry.js
1 year ago
sc-upsell-countdown-timer.entry.js.map
1 year ago
sc-upsell-no-thanks-button.entry.js
1 year ago
sc-upsell-no-thanks-button.entry.js.map
1 year ago
sc-upsell-submit-button.entry.js
1 year ago
sc-upsell-submit-button.entry.js.map
1 year ago
sc-upsell-totals.entry.js
1 year ago
sc-upsell-totals.entry.js.map
1 year ago
sc-upsell.entry.js
1 year ago
sc-upsell.entry.js.map
1 year ago
sc-visually-hidden.entry.js
1 year ago
sc-visually-hidden.entry.js.map
1 year ago
sc-wordpress-password-edit.entry.js
1 year ago
sc-wordpress-password-edit.entry.js.map
1 year ago
sc-wordpress-user-edit.entry.js
1 year ago
sc-wordpress-user-edit.entry.js.map
1 year ago
sc-wordpress-user.entry.js
1 year ago
sc-wordpress-user.entry.js.map
1 year ago
store-7020541e.js
1 year ago
store-7020541e.js.map
1 year ago
store-a8bae355.js
1 year ago
store-a8bae355.js.map
1 year ago
store-dcefd119.js
1 year ago
store-dcefd119.js.map
1 year ago
surecart.js
1 year ago
surecart.js.map
1 year ago
tax-d4911dbc.js
1 year ago
tax-d4911dbc.js.map
1 year ago
universe-5a73abb7.js
1 year ago
universe-5a73abb7.js.map
1 year ago
util-50af2a83.js
1 year ago
util-50af2a83.js.map
1 year ago
utils-e9ee502a.js
1 year ago
utils-e9ee502a.js.map
1 year ago
watchers-38693c1f.js
1 year ago
watchers-38693c1f.js.map
1 year ago
watchers-46ca00a4.js
1 year ago
watchers-46ca00a4.js.map
1 year ago
watchers-67501779.js
1 year ago
watchers-67501779.js.map
1 year ago
watchers-94c3ca47.js
1 year ago
watchers-94c3ca47.js.map
1 year ago
watchers-bbcb6e4d.js
1 year ago
watchers-bbcb6e4d.js.map
1 year ago
sc-menu-label_2.entry.js
2095 lines
| 1 | import { r as registerInstance, h, c as createEvent, a as getElement } from './index-745b6bec.js'; |
| 2 | import { F as FormSubmitController } from './form-data-76641f16.js'; |
| 3 | import { b as isValidURL } from './util-50af2a83.js'; |
| 4 | |
| 5 | const scMenuLabelCss = ":host{display:block}.menu-label{font-family:var(--sc-font-sans);font-size:var(--sc-font-size-x-small);font-weight:var(--sc-font-weight-semibold);line-height:var(--sc-line-height-normal);letter-spacing:var(--sc-letter-spacing-normal);color:var(--sc-color-gray-500);padding:var(--sc-spacing-small) var(--sc-spacing-large);user-select:none;text-transform:uppercase}"; |
| 6 | const ScMenuLabelStyle0 = scMenuLabelCss; |
| 7 | |
| 8 | const ScMenuLabel = class { |
| 9 | constructor(hostRef) { |
| 10 | registerInstance(this, hostRef); |
| 11 | } |
| 12 | render() { |
| 13 | return (h("div", { key: 'ec6629a4c6e8873907249335f49ae48ce3e5ef25', part: "base", class: "menu-label" }, h("slot", { key: 'a541eddf938bdf31430e690a0881de84476af1e9' }))); |
| 14 | } |
| 15 | }; |
| 16 | ScMenuLabel.style = ScMenuLabelStyle0; |
| 17 | |
| 18 | /** |
| 19 | * Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io) |
| 20 | * |
| 21 | * Copyright (c) 2022 Kiro Risk (http://kiro.me) |
| 22 | * All Rights Reserved. Apache Software License 2.0 |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | */ |
| 26 | |
| 27 | function isArray(value) { |
| 28 | return !Array.isArray |
| 29 | ? getTag(value) === '[object Array]' |
| 30 | : Array.isArray(value) |
| 31 | } |
| 32 | |
| 33 | // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js |
| 34 | const INFINITY = 1 / 0; |
| 35 | function baseToString(value) { |
| 36 | // Exit early for strings to avoid a performance hit in some environments. |
| 37 | if (typeof value == 'string') { |
| 38 | return value |
| 39 | } |
| 40 | let result = value + ''; |
| 41 | return result == '0' && 1 / value == -INFINITY ? '-0' : result |
| 42 | } |
| 43 | |
| 44 | function toString(value) { |
| 45 | return value == null ? '' : baseToString(value) |
| 46 | } |
| 47 | |
| 48 | function isString(value) { |
| 49 | return typeof value === 'string' |
| 50 | } |
| 51 | |
| 52 | function isNumber(value) { |
| 53 | return typeof value === 'number' |
| 54 | } |
| 55 | |
| 56 | // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js |
| 57 | function isBoolean(value) { |
| 58 | return ( |
| 59 | value === true || |
| 60 | value === false || |
| 61 | (isObjectLike(value) && getTag(value) == '[object Boolean]') |
| 62 | ) |
| 63 | } |
| 64 | |
| 65 | function isObject(value) { |
| 66 | return typeof value === 'object' |
| 67 | } |
| 68 | |
| 69 | // Checks if `value` is object-like. |
| 70 | function isObjectLike(value) { |
| 71 | return isObject(value) && value !== null |
| 72 | } |
| 73 | |
| 74 | function isDefined(value) { |
| 75 | return value !== undefined && value !== null |
| 76 | } |
| 77 | |
| 78 | function isBlank(value) { |
| 79 | return !value.trim().length |
| 80 | } |
| 81 | |
| 82 | // Gets the `toStringTag` of `value`. |
| 83 | // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js |
| 84 | function getTag(value) { |
| 85 | return value == null |
| 86 | ? value === undefined |
| 87 | ? '[object Undefined]' |
| 88 | : '[object Null]' |
| 89 | : Object.prototype.toString.call(value) |
| 90 | } |
| 91 | |
| 92 | const EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; |
| 93 | |
| 94 | const INCORRECT_INDEX_TYPE = "Incorrect 'index' type"; |
| 95 | |
| 96 | const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => |
| 97 | `Invalid value for key ${key}`; |
| 98 | |
| 99 | const PATTERN_LENGTH_TOO_LARGE = (max) => |
| 100 | `Pattern length exceeds max of ${max}.`; |
| 101 | |
| 102 | const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`; |
| 103 | |
| 104 | const INVALID_KEY_WEIGHT_VALUE = (key) => |
| 105 | `Property 'weight' in key '${key}' must be a positive integer`; |
| 106 | |
| 107 | const hasOwn = Object.prototype.hasOwnProperty; |
| 108 | |
| 109 | class KeyStore { |
| 110 | constructor(keys) { |
| 111 | this._keys = []; |
| 112 | this._keyMap = {}; |
| 113 | |
| 114 | let totalWeight = 0; |
| 115 | |
| 116 | keys.forEach((key) => { |
| 117 | let obj = createKey(key); |
| 118 | |
| 119 | totalWeight += obj.weight; |
| 120 | |
| 121 | this._keys.push(obj); |
| 122 | this._keyMap[obj.id] = obj; |
| 123 | |
| 124 | totalWeight += obj.weight; |
| 125 | }); |
| 126 | |
| 127 | // Normalize weights so that their sum is equal to 1 |
| 128 | this._keys.forEach((key) => { |
| 129 | key.weight /= totalWeight; |
| 130 | }); |
| 131 | } |
| 132 | get(keyId) { |
| 133 | return this._keyMap[keyId] |
| 134 | } |
| 135 | keys() { |
| 136 | return this._keys |
| 137 | } |
| 138 | toJSON() { |
| 139 | return JSON.stringify(this._keys) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | function createKey(key) { |
| 144 | let path = null; |
| 145 | let id = null; |
| 146 | let src = null; |
| 147 | let weight = 1; |
| 148 | let getFn = null; |
| 149 | |
| 150 | if (isString(key) || isArray(key)) { |
| 151 | src = key; |
| 152 | path = createKeyPath(key); |
| 153 | id = createKeyId(key); |
| 154 | } else { |
| 155 | if (!hasOwn.call(key, 'name')) { |
| 156 | throw new Error(MISSING_KEY_PROPERTY('name')) |
| 157 | } |
| 158 | |
| 159 | const name = key.name; |
| 160 | src = name; |
| 161 | |
| 162 | if (hasOwn.call(key, 'weight')) { |
| 163 | weight = key.weight; |
| 164 | |
| 165 | if (weight <= 0) { |
| 166 | throw new Error(INVALID_KEY_WEIGHT_VALUE(name)) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | path = createKeyPath(name); |
| 171 | id = createKeyId(name); |
| 172 | getFn = key.getFn; |
| 173 | } |
| 174 | |
| 175 | return { path, id, weight, src, getFn } |
| 176 | } |
| 177 | |
| 178 | function createKeyPath(key) { |
| 179 | return isArray(key) ? key : key.split('.') |
| 180 | } |
| 181 | |
| 182 | function createKeyId(key) { |
| 183 | return isArray(key) ? key.join('.') : key |
| 184 | } |
| 185 | |
| 186 | function get(obj, path) { |
| 187 | let list = []; |
| 188 | let arr = false; |
| 189 | |
| 190 | const deepGet = (obj, path, index) => { |
| 191 | if (!isDefined(obj)) { |
| 192 | return |
| 193 | } |
| 194 | if (!path[index]) { |
| 195 | // If there's no path left, we've arrived at the object we care about. |
| 196 | list.push(obj); |
| 197 | } else { |
| 198 | let key = path[index]; |
| 199 | |
| 200 | const value = obj[key]; |
| 201 | |
| 202 | if (!isDefined(value)) { |
| 203 | return |
| 204 | } |
| 205 | |
| 206 | // If we're at the last value in the path, and if it's a string/number/bool, |
| 207 | // add it to the list |
| 208 | if ( |
| 209 | index === path.length - 1 && |
| 210 | (isString(value) || isNumber(value) || isBoolean(value)) |
| 211 | ) { |
| 212 | list.push(toString(value)); |
| 213 | } else if (isArray(value)) { |
| 214 | arr = true; |
| 215 | // Search each item in the array. |
| 216 | for (let i = 0, len = value.length; i < len; i += 1) { |
| 217 | deepGet(value[i], path, index + 1); |
| 218 | } |
| 219 | } else if (path.length) { |
| 220 | // An object. Recurse further. |
| 221 | deepGet(value, path, index + 1); |
| 222 | } |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | // Backwards compatibility (since path used to be a string) |
| 227 | deepGet(obj, isString(path) ? path.split('.') : path, 0); |
| 228 | |
| 229 | return arr ? list : list[0] |
| 230 | } |
| 231 | |
| 232 | const MatchOptions = { |
| 233 | // Whether the matches should be included in the result set. When `true`, each record in the result |
| 234 | // set will include the indices of the matched characters. |
| 235 | // These can consequently be used for highlighting purposes. |
| 236 | includeMatches: false, |
| 237 | // When `true`, the matching function will continue to the end of a search pattern even if |
| 238 | // a perfect match has already been located in the string. |
| 239 | findAllMatches: false, |
| 240 | // Minimum number of characters that must be matched before a result is considered a match |
| 241 | minMatchCharLength: 1 |
| 242 | }; |
| 243 | |
| 244 | const BasicOptions = { |
| 245 | // When `true`, the algorithm continues searching to the end of the input even if a perfect |
| 246 | // match is found before the end of the same input. |
| 247 | isCaseSensitive: false, |
| 248 | // When true, the matching function will continue to the end of a search pattern even if |
| 249 | includeScore: false, |
| 250 | // List of properties that will be searched. This also supports nested properties. |
| 251 | keys: [], |
| 252 | // Whether to sort the result list, by score |
| 253 | shouldSort: true, |
| 254 | // Default sort function: sort by ascending score, ascending index |
| 255 | sortFn: (a, b) => |
| 256 | a.score === b.score ? (a.idx < b.idx ? -1 : 1) : a.score < b.score ? -1 : 1 |
| 257 | }; |
| 258 | |
| 259 | const FuzzyOptions = { |
| 260 | // Approximately where in the text is the pattern expected to be found? |
| 261 | location: 0, |
| 262 | // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match |
| 263 | // (of both letters and location), a threshold of '1.0' would match anything. |
| 264 | threshold: 0.6, |
| 265 | // Determines how close the match must be to the fuzzy location (specified above). |
| 266 | // An exact letter match which is 'distance' characters away from the fuzzy location |
| 267 | // would score as a complete mismatch. A distance of '0' requires the match be at |
| 268 | // the exact location specified, a threshold of '1000' would require a perfect match |
| 269 | // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. |
| 270 | distance: 100 |
| 271 | }; |
| 272 | |
| 273 | const AdvancedOptions = { |
| 274 | // When `true`, it enables the use of unix-like search commands |
| 275 | useExtendedSearch: false, |
| 276 | // The get function to use when fetching an object's properties. |
| 277 | // The default will search nested paths *ie foo.bar.baz* |
| 278 | getFn: get, |
| 279 | // When `true`, search will ignore `location` and `distance`, so it won't matter |
| 280 | // where in the string the pattern appears. |
| 281 | // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score |
| 282 | ignoreLocation: false, |
| 283 | // When `true`, the calculation for the relevance score (used for sorting) will |
| 284 | // ignore the field-length norm. |
| 285 | // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm |
| 286 | ignoreFieldNorm: false, |
| 287 | // The weight to determine how much field length norm effects scoring. |
| 288 | fieldNormWeight: 1 |
| 289 | }; |
| 290 | |
| 291 | var Config = { |
| 292 | ...BasicOptions, |
| 293 | ...MatchOptions, |
| 294 | ...FuzzyOptions, |
| 295 | ...AdvancedOptions |
| 296 | }; |
| 297 | |
| 298 | const SPACE = /[^ ]+/g; |
| 299 | |
| 300 | // Field-length norm: the shorter the field, the higher the weight. |
| 301 | // Set to 3 decimals to reduce index size. |
| 302 | function norm(weight = 1, mantissa = 3) { |
| 303 | const cache = new Map(); |
| 304 | const m = Math.pow(10, mantissa); |
| 305 | |
| 306 | return { |
| 307 | get(value) { |
| 308 | const numTokens = value.match(SPACE).length; |
| 309 | |
| 310 | if (cache.has(numTokens)) { |
| 311 | return cache.get(numTokens) |
| 312 | } |
| 313 | |
| 314 | // Default function is 1/sqrt(x), weight makes that variable |
| 315 | const norm = 1 / Math.pow(numTokens, 0.5 * weight); |
| 316 | |
| 317 | // In place of `toFixed(mantissa)`, for faster computation |
| 318 | const n = parseFloat(Math.round(norm * m) / m); |
| 319 | |
| 320 | cache.set(numTokens, n); |
| 321 | |
| 322 | return n |
| 323 | }, |
| 324 | clear() { |
| 325 | cache.clear(); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | class FuseIndex { |
| 331 | constructor({ |
| 332 | getFn = Config.getFn, |
| 333 | fieldNormWeight = Config.fieldNormWeight |
| 334 | } = {}) { |
| 335 | this.norm = norm(fieldNormWeight, 3); |
| 336 | this.getFn = getFn; |
| 337 | this.isCreated = false; |
| 338 | |
| 339 | this.setIndexRecords(); |
| 340 | } |
| 341 | setSources(docs = []) { |
| 342 | this.docs = docs; |
| 343 | } |
| 344 | setIndexRecords(records = []) { |
| 345 | this.records = records; |
| 346 | } |
| 347 | setKeys(keys = []) { |
| 348 | this.keys = keys; |
| 349 | this._keysMap = {}; |
| 350 | keys.forEach((key, idx) => { |
| 351 | this._keysMap[key.id] = idx; |
| 352 | }); |
| 353 | } |
| 354 | create() { |
| 355 | if (this.isCreated || !this.docs.length) { |
| 356 | return |
| 357 | } |
| 358 | |
| 359 | this.isCreated = true; |
| 360 | |
| 361 | // List is Array<String> |
| 362 | if (isString(this.docs[0])) { |
| 363 | this.docs.forEach((doc, docIndex) => { |
| 364 | this._addString(doc, docIndex); |
| 365 | }); |
| 366 | } else { |
| 367 | // List is Array<Object> |
| 368 | this.docs.forEach((doc, docIndex) => { |
| 369 | this._addObject(doc, docIndex); |
| 370 | }); |
| 371 | } |
| 372 | |
| 373 | this.norm.clear(); |
| 374 | } |
| 375 | // Adds a doc to the end of the index |
| 376 | add(doc) { |
| 377 | const idx = this.size(); |
| 378 | |
| 379 | if (isString(doc)) { |
| 380 | this._addString(doc, idx); |
| 381 | } else { |
| 382 | this._addObject(doc, idx); |
| 383 | } |
| 384 | } |
| 385 | // Removes the doc at the specified index of the index |
| 386 | removeAt(idx) { |
| 387 | this.records.splice(idx, 1); |
| 388 | |
| 389 | // Change ref index of every subsquent doc |
| 390 | for (let i = idx, len = this.size(); i < len; i += 1) { |
| 391 | this.records[i].i -= 1; |
| 392 | } |
| 393 | } |
| 394 | getValueForItemAtKeyId(item, keyId) { |
| 395 | return item[this._keysMap[keyId]] |
| 396 | } |
| 397 | size() { |
| 398 | return this.records.length |
| 399 | } |
| 400 | _addString(doc, docIndex) { |
| 401 | if (!isDefined(doc) || isBlank(doc)) { |
| 402 | return |
| 403 | } |
| 404 | |
| 405 | let record = { |
| 406 | v: doc, |
| 407 | i: docIndex, |
| 408 | n: this.norm.get(doc) |
| 409 | }; |
| 410 | |
| 411 | this.records.push(record); |
| 412 | } |
| 413 | _addObject(doc, docIndex) { |
| 414 | let record = { i: docIndex, $: {} }; |
| 415 | |
| 416 | // Iterate over every key (i.e, path), and fetch the value at that key |
| 417 | this.keys.forEach((key, keyIndex) => { |
| 418 | let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path); |
| 419 | |
| 420 | if (!isDefined(value)) { |
| 421 | return |
| 422 | } |
| 423 | |
| 424 | if (isArray(value)) { |
| 425 | let subRecords = []; |
| 426 | const stack = [{ nestedArrIndex: -1, value }]; |
| 427 | |
| 428 | while (stack.length) { |
| 429 | const { nestedArrIndex, value } = stack.pop(); |
| 430 | |
| 431 | if (!isDefined(value)) { |
| 432 | continue |
| 433 | } |
| 434 | |
| 435 | if (isString(value) && !isBlank(value)) { |
| 436 | let subRecord = { |
| 437 | v: value, |
| 438 | i: nestedArrIndex, |
| 439 | n: this.norm.get(value) |
| 440 | }; |
| 441 | |
| 442 | subRecords.push(subRecord); |
| 443 | } else if (isArray(value)) { |
| 444 | value.forEach((item, k) => { |
| 445 | stack.push({ |
| 446 | nestedArrIndex: k, |
| 447 | value: item |
| 448 | }); |
| 449 | }); |
| 450 | } else ; |
| 451 | } |
| 452 | record.$[keyIndex] = subRecords; |
| 453 | } else if (isString(value) && !isBlank(value)) { |
| 454 | let subRecord = { |
| 455 | v: value, |
| 456 | n: this.norm.get(value) |
| 457 | }; |
| 458 | |
| 459 | record.$[keyIndex] = subRecord; |
| 460 | } |
| 461 | }); |
| 462 | |
| 463 | this.records.push(record); |
| 464 | } |
| 465 | toJSON() { |
| 466 | return { |
| 467 | keys: this.keys, |
| 468 | records: this.records |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | function createIndex( |
| 474 | keys, |
| 475 | docs, |
| 476 | { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {} |
| 477 | ) { |
| 478 | const myIndex = new FuseIndex({ getFn, fieldNormWeight }); |
| 479 | myIndex.setKeys(keys.map(createKey)); |
| 480 | myIndex.setSources(docs); |
| 481 | myIndex.create(); |
| 482 | return myIndex |
| 483 | } |
| 484 | |
| 485 | function parseIndex( |
| 486 | data, |
| 487 | { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {} |
| 488 | ) { |
| 489 | const { keys, records } = data; |
| 490 | const myIndex = new FuseIndex({ getFn, fieldNormWeight }); |
| 491 | myIndex.setKeys(keys); |
| 492 | myIndex.setIndexRecords(records); |
| 493 | return myIndex |
| 494 | } |
| 495 | |
| 496 | function computeScore$1( |
| 497 | pattern, |
| 498 | { |
| 499 | errors = 0, |
| 500 | currentLocation = 0, |
| 501 | expectedLocation = 0, |
| 502 | distance = Config.distance, |
| 503 | ignoreLocation = Config.ignoreLocation |
| 504 | } = {} |
| 505 | ) { |
| 506 | const accuracy = errors / pattern.length; |
| 507 | |
| 508 | if (ignoreLocation) { |
| 509 | return accuracy |
| 510 | } |
| 511 | |
| 512 | const proximity = Math.abs(expectedLocation - currentLocation); |
| 513 | |
| 514 | if (!distance) { |
| 515 | // Dodge divide by zero error. |
| 516 | return proximity ? 1.0 : accuracy |
| 517 | } |
| 518 | |
| 519 | return accuracy + proximity / distance |
| 520 | } |
| 521 | |
| 522 | function convertMaskToIndices( |
| 523 | matchmask = [], |
| 524 | minMatchCharLength = Config.minMatchCharLength |
| 525 | ) { |
| 526 | let indices = []; |
| 527 | let start = -1; |
| 528 | let end = -1; |
| 529 | let i = 0; |
| 530 | |
| 531 | for (let len = matchmask.length; i < len; i += 1) { |
| 532 | let match = matchmask[i]; |
| 533 | if (match && start === -1) { |
| 534 | start = i; |
| 535 | } else if (!match && start !== -1) { |
| 536 | end = i - 1; |
| 537 | if (end - start + 1 >= minMatchCharLength) { |
| 538 | indices.push([start, end]); |
| 539 | } |
| 540 | start = -1; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // (i-1 - start) + 1 => i - start |
| 545 | if (matchmask[i - 1] && i - start >= minMatchCharLength) { |
| 546 | indices.push([start, i - 1]); |
| 547 | } |
| 548 | |
| 549 | return indices |
| 550 | } |
| 551 | |
| 552 | // Machine word size |
| 553 | const MAX_BITS = 32; |
| 554 | |
| 555 | function search( |
| 556 | text, |
| 557 | pattern, |
| 558 | patternAlphabet, |
| 559 | { |
| 560 | location = Config.location, |
| 561 | distance = Config.distance, |
| 562 | threshold = Config.threshold, |
| 563 | findAllMatches = Config.findAllMatches, |
| 564 | minMatchCharLength = Config.minMatchCharLength, |
| 565 | includeMatches = Config.includeMatches, |
| 566 | ignoreLocation = Config.ignoreLocation |
| 567 | } = {} |
| 568 | ) { |
| 569 | if (pattern.length > MAX_BITS) { |
| 570 | throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS)) |
| 571 | } |
| 572 | |
| 573 | const patternLen = pattern.length; |
| 574 | // Set starting location at beginning text and initialize the alphabet. |
| 575 | const textLen = text.length; |
| 576 | // Handle the case when location > text.length |
| 577 | const expectedLocation = Math.max(0, Math.min(location, textLen)); |
| 578 | // Highest score beyond which we give up. |
| 579 | let currentThreshold = threshold; |
| 580 | // Is there a nearby exact match? (speedup) |
| 581 | let bestLocation = expectedLocation; |
| 582 | |
| 583 | // Performance: only computer matches when the minMatchCharLength > 1 |
| 584 | // OR if `includeMatches` is true. |
| 585 | const computeMatches = minMatchCharLength > 1 || includeMatches; |
| 586 | // A mask of the matches, used for building the indices |
| 587 | const matchMask = computeMatches ? Array(textLen) : []; |
| 588 | |
| 589 | let index; |
| 590 | |
| 591 | // Get all exact matches, here for speed up |
| 592 | while ((index = text.indexOf(pattern, bestLocation)) > -1) { |
| 593 | let score = computeScore$1(pattern, { |
| 594 | currentLocation: index, |
| 595 | expectedLocation, |
| 596 | distance, |
| 597 | ignoreLocation |
| 598 | }); |
| 599 | |
| 600 | currentThreshold = Math.min(score, currentThreshold); |
| 601 | bestLocation = index + patternLen; |
| 602 | |
| 603 | if (computeMatches) { |
| 604 | let i = 0; |
| 605 | while (i < patternLen) { |
| 606 | matchMask[index + i] = 1; |
| 607 | i += 1; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Reset the best location |
| 613 | bestLocation = -1; |
| 614 | |
| 615 | let lastBitArr = []; |
| 616 | let finalScore = 1; |
| 617 | let binMax = patternLen + textLen; |
| 618 | |
| 619 | const mask = 1 << (patternLen - 1); |
| 620 | |
| 621 | for (let i = 0; i < patternLen; i += 1) { |
| 622 | // Scan for the best match; each iteration allows for one more error. |
| 623 | // Run a binary search to determine how far from the match location we can stray |
| 624 | // at this error level. |
| 625 | let binMin = 0; |
| 626 | let binMid = binMax; |
| 627 | |
| 628 | while (binMin < binMid) { |
| 629 | const score = computeScore$1(pattern, { |
| 630 | errors: i, |
| 631 | currentLocation: expectedLocation + binMid, |
| 632 | expectedLocation, |
| 633 | distance, |
| 634 | ignoreLocation |
| 635 | }); |
| 636 | |
| 637 | if (score <= currentThreshold) { |
| 638 | binMin = binMid; |
| 639 | } else { |
| 640 | binMax = binMid; |
| 641 | } |
| 642 | |
| 643 | binMid = Math.floor((binMax - binMin) / 2 + binMin); |
| 644 | } |
| 645 | |
| 646 | // Use the result from this iteration as the maximum for the next. |
| 647 | binMax = binMid; |
| 648 | |
| 649 | let start = Math.max(1, expectedLocation - binMid + 1); |
| 650 | let finish = findAllMatches |
| 651 | ? textLen |
| 652 | : Math.min(expectedLocation + binMid, textLen) + patternLen; |
| 653 | |
| 654 | // Initialize the bit array |
| 655 | let bitArr = Array(finish + 2); |
| 656 | |
| 657 | bitArr[finish + 1] = (1 << i) - 1; |
| 658 | |
| 659 | for (let j = finish; j >= start; j -= 1) { |
| 660 | let currentLocation = j - 1; |
| 661 | let charMatch = patternAlphabet[text.charAt(currentLocation)]; |
| 662 | |
| 663 | if (computeMatches) { |
| 664 | // Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`) |
| 665 | matchMask[currentLocation] = +!!charMatch; |
| 666 | } |
| 667 | |
| 668 | // First pass: exact match |
| 669 | bitArr[j] = ((bitArr[j + 1] << 1) | 1) & charMatch; |
| 670 | |
| 671 | // Subsequent passes: fuzzy match |
| 672 | if (i) { |
| 673 | bitArr[j] |= |
| 674 | ((lastBitArr[j + 1] | lastBitArr[j]) << 1) | 1 | lastBitArr[j + 1]; |
| 675 | } |
| 676 | |
| 677 | if (bitArr[j] & mask) { |
| 678 | finalScore = computeScore$1(pattern, { |
| 679 | errors: i, |
| 680 | currentLocation, |
| 681 | expectedLocation, |
| 682 | distance, |
| 683 | ignoreLocation |
| 684 | }); |
| 685 | |
| 686 | // This match will almost certainly be better than any existing match. |
| 687 | // But check anyway. |
| 688 | if (finalScore <= currentThreshold) { |
| 689 | // Indeed it is |
| 690 | currentThreshold = finalScore; |
| 691 | bestLocation = currentLocation; |
| 692 | |
| 693 | // Already passed `loc`, downhill from here on in. |
| 694 | if (bestLocation <= expectedLocation) { |
| 695 | break |
| 696 | } |
| 697 | |
| 698 | // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`. |
| 699 | start = Math.max(1, 2 * expectedLocation - bestLocation); |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | // No hope for a (better) match at greater error levels. |
| 705 | const score = computeScore$1(pattern, { |
| 706 | errors: i + 1, |
| 707 | currentLocation: expectedLocation, |
| 708 | expectedLocation, |
| 709 | distance, |
| 710 | ignoreLocation |
| 711 | }); |
| 712 | |
| 713 | if (score > currentThreshold) { |
| 714 | break |
| 715 | } |
| 716 | |
| 717 | lastBitArr = bitArr; |
| 718 | } |
| 719 | |
| 720 | const result = { |
| 721 | isMatch: bestLocation >= 0, |
| 722 | // Count exact matches (those with a score of 0) to be "almost" exact |
| 723 | score: Math.max(0.001, finalScore) |
| 724 | }; |
| 725 | |
| 726 | if (computeMatches) { |
| 727 | const indices = convertMaskToIndices(matchMask, minMatchCharLength); |
| 728 | if (!indices.length) { |
| 729 | result.isMatch = false; |
| 730 | } else if (includeMatches) { |
| 731 | result.indices = indices; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | return result |
| 736 | } |
| 737 | |
| 738 | function createPatternAlphabet(pattern) { |
| 739 | let mask = {}; |
| 740 | |
| 741 | for (let i = 0, len = pattern.length; i < len; i += 1) { |
| 742 | const char = pattern.charAt(i); |
| 743 | mask[char] = (mask[char] || 0) | (1 << (len - i - 1)); |
| 744 | } |
| 745 | |
| 746 | return mask |
| 747 | } |
| 748 | |
| 749 | class BitapSearch { |
| 750 | constructor( |
| 751 | pattern, |
| 752 | { |
| 753 | location = Config.location, |
| 754 | threshold = Config.threshold, |
| 755 | distance = Config.distance, |
| 756 | includeMatches = Config.includeMatches, |
| 757 | findAllMatches = Config.findAllMatches, |
| 758 | minMatchCharLength = Config.minMatchCharLength, |
| 759 | isCaseSensitive = Config.isCaseSensitive, |
| 760 | ignoreLocation = Config.ignoreLocation |
| 761 | } = {} |
| 762 | ) { |
| 763 | this.options = { |
| 764 | location, |
| 765 | threshold, |
| 766 | distance, |
| 767 | includeMatches, |
| 768 | findAllMatches, |
| 769 | minMatchCharLength, |
| 770 | isCaseSensitive, |
| 771 | ignoreLocation |
| 772 | }; |
| 773 | |
| 774 | this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); |
| 775 | |
| 776 | this.chunks = []; |
| 777 | |
| 778 | if (!this.pattern.length) { |
| 779 | return |
| 780 | } |
| 781 | |
| 782 | const addChunk = (pattern, startIndex) => { |
| 783 | this.chunks.push({ |
| 784 | pattern, |
| 785 | alphabet: createPatternAlphabet(pattern), |
| 786 | startIndex |
| 787 | }); |
| 788 | }; |
| 789 | |
| 790 | const len = this.pattern.length; |
| 791 | |
| 792 | if (len > MAX_BITS) { |
| 793 | let i = 0; |
| 794 | const remainder = len % MAX_BITS; |
| 795 | const end = len - remainder; |
| 796 | |
| 797 | while (i < end) { |
| 798 | addChunk(this.pattern.substr(i, MAX_BITS), i); |
| 799 | i += MAX_BITS; |
| 800 | } |
| 801 | |
| 802 | if (remainder) { |
| 803 | const startIndex = len - MAX_BITS; |
| 804 | addChunk(this.pattern.substr(startIndex), startIndex); |
| 805 | } |
| 806 | } else { |
| 807 | addChunk(this.pattern, 0); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | searchIn(text) { |
| 812 | const { isCaseSensitive, includeMatches } = this.options; |
| 813 | |
| 814 | if (!isCaseSensitive) { |
| 815 | text = text.toLowerCase(); |
| 816 | } |
| 817 | |
| 818 | // Exact match |
| 819 | if (this.pattern === text) { |
| 820 | let result = { |
| 821 | isMatch: true, |
| 822 | score: 0 |
| 823 | }; |
| 824 | |
| 825 | if (includeMatches) { |
| 826 | result.indices = [[0, text.length - 1]]; |
| 827 | } |
| 828 | |
| 829 | return result |
| 830 | } |
| 831 | |
| 832 | // Otherwise, use Bitap algorithm |
| 833 | const { |
| 834 | location, |
| 835 | distance, |
| 836 | threshold, |
| 837 | findAllMatches, |
| 838 | minMatchCharLength, |
| 839 | ignoreLocation |
| 840 | } = this.options; |
| 841 | |
| 842 | let allIndices = []; |
| 843 | let totalScore = 0; |
| 844 | let hasMatches = false; |
| 845 | |
| 846 | this.chunks.forEach(({ pattern, alphabet, startIndex }) => { |
| 847 | const { isMatch, score, indices } = search(text, pattern, alphabet, { |
| 848 | location: location + startIndex, |
| 849 | distance, |
| 850 | threshold, |
| 851 | findAllMatches, |
| 852 | minMatchCharLength, |
| 853 | includeMatches, |
| 854 | ignoreLocation |
| 855 | }); |
| 856 | |
| 857 | if (isMatch) { |
| 858 | hasMatches = true; |
| 859 | } |
| 860 | |
| 861 | totalScore += score; |
| 862 | |
| 863 | if (isMatch && indices) { |
| 864 | allIndices = [...allIndices, ...indices]; |
| 865 | } |
| 866 | }); |
| 867 | |
| 868 | let result = { |
| 869 | isMatch: hasMatches, |
| 870 | score: hasMatches ? totalScore / this.chunks.length : 1 |
| 871 | }; |
| 872 | |
| 873 | if (hasMatches && includeMatches) { |
| 874 | result.indices = allIndices; |
| 875 | } |
| 876 | |
| 877 | return result |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | class BaseMatch { |
| 882 | constructor(pattern) { |
| 883 | this.pattern = pattern; |
| 884 | } |
| 885 | static isMultiMatch(pattern) { |
| 886 | return getMatch(pattern, this.multiRegex) |
| 887 | } |
| 888 | static isSingleMatch(pattern) { |
| 889 | return getMatch(pattern, this.singleRegex) |
| 890 | } |
| 891 | search(/*text*/) {} |
| 892 | } |
| 893 | |
| 894 | function getMatch(pattern, exp) { |
| 895 | const matches = pattern.match(exp); |
| 896 | return matches ? matches[1] : null |
| 897 | } |
| 898 | |
| 899 | // Token: 'file |
| 900 | |
| 901 | class ExactMatch extends BaseMatch { |
| 902 | constructor(pattern) { |
| 903 | super(pattern); |
| 904 | } |
| 905 | static get type() { |
| 906 | return 'exact' |
| 907 | } |
| 908 | static get multiRegex() { |
| 909 | return /^="(.*)"$/ |
| 910 | } |
| 911 | static get singleRegex() { |
| 912 | return /^=(.*)$/ |
| 913 | } |
| 914 | search(text) { |
| 915 | const isMatch = text === this.pattern; |
| 916 | |
| 917 | return { |
| 918 | isMatch, |
| 919 | score: isMatch ? 0 : 1, |
| 920 | indices: [0, this.pattern.length - 1] |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | // Token: !fire |
| 926 | |
| 927 | class InverseExactMatch extends BaseMatch { |
| 928 | constructor(pattern) { |
| 929 | super(pattern); |
| 930 | } |
| 931 | static get type() { |
| 932 | return 'inverse-exact' |
| 933 | } |
| 934 | static get multiRegex() { |
| 935 | return /^!"(.*)"$/ |
| 936 | } |
| 937 | static get singleRegex() { |
| 938 | return /^!(.*)$/ |
| 939 | } |
| 940 | search(text) { |
| 941 | const index = text.indexOf(this.pattern); |
| 942 | const isMatch = index === -1; |
| 943 | |
| 944 | return { |
| 945 | isMatch, |
| 946 | score: isMatch ? 0 : 1, |
| 947 | indices: [0, text.length - 1] |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | // Token: ^file |
| 953 | |
| 954 | class PrefixExactMatch extends BaseMatch { |
| 955 | constructor(pattern) { |
| 956 | super(pattern); |
| 957 | } |
| 958 | static get type() { |
| 959 | return 'prefix-exact' |
| 960 | } |
| 961 | static get multiRegex() { |
| 962 | return /^\^"(.*)"$/ |
| 963 | } |
| 964 | static get singleRegex() { |
| 965 | return /^\^(.*)$/ |
| 966 | } |
| 967 | search(text) { |
| 968 | const isMatch = text.startsWith(this.pattern); |
| 969 | |
| 970 | return { |
| 971 | isMatch, |
| 972 | score: isMatch ? 0 : 1, |
| 973 | indices: [0, this.pattern.length - 1] |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | // Token: !^fire |
| 979 | |
| 980 | class InversePrefixExactMatch extends BaseMatch { |
| 981 | constructor(pattern) { |
| 982 | super(pattern); |
| 983 | } |
| 984 | static get type() { |
| 985 | return 'inverse-prefix-exact' |
| 986 | } |
| 987 | static get multiRegex() { |
| 988 | return /^!\^"(.*)"$/ |
| 989 | } |
| 990 | static get singleRegex() { |
| 991 | return /^!\^(.*)$/ |
| 992 | } |
| 993 | search(text) { |
| 994 | const isMatch = !text.startsWith(this.pattern); |
| 995 | |
| 996 | return { |
| 997 | isMatch, |
| 998 | score: isMatch ? 0 : 1, |
| 999 | indices: [0, text.length - 1] |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | // Token: .file$ |
| 1005 | |
| 1006 | class SuffixExactMatch extends BaseMatch { |
| 1007 | constructor(pattern) { |
| 1008 | super(pattern); |
| 1009 | } |
| 1010 | static get type() { |
| 1011 | return 'suffix-exact' |
| 1012 | } |
| 1013 | static get multiRegex() { |
| 1014 | return /^"(.*)"\$$/ |
| 1015 | } |
| 1016 | static get singleRegex() { |
| 1017 | return /^(.*)\$$/ |
| 1018 | } |
| 1019 | search(text) { |
| 1020 | const isMatch = text.endsWith(this.pattern); |
| 1021 | |
| 1022 | return { |
| 1023 | isMatch, |
| 1024 | score: isMatch ? 0 : 1, |
| 1025 | indices: [text.length - this.pattern.length, text.length - 1] |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | // Token: !.file$ |
| 1031 | |
| 1032 | class InverseSuffixExactMatch extends BaseMatch { |
| 1033 | constructor(pattern) { |
| 1034 | super(pattern); |
| 1035 | } |
| 1036 | static get type() { |
| 1037 | return 'inverse-suffix-exact' |
| 1038 | } |
| 1039 | static get multiRegex() { |
| 1040 | return /^!"(.*)"\$$/ |
| 1041 | } |
| 1042 | static get singleRegex() { |
| 1043 | return /^!(.*)\$$/ |
| 1044 | } |
| 1045 | search(text) { |
| 1046 | const isMatch = !text.endsWith(this.pattern); |
| 1047 | return { |
| 1048 | isMatch, |
| 1049 | score: isMatch ? 0 : 1, |
| 1050 | indices: [0, text.length - 1] |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | class FuzzyMatch extends BaseMatch { |
| 1056 | constructor( |
| 1057 | pattern, |
| 1058 | { |
| 1059 | location = Config.location, |
| 1060 | threshold = Config.threshold, |
| 1061 | distance = Config.distance, |
| 1062 | includeMatches = Config.includeMatches, |
| 1063 | findAllMatches = Config.findAllMatches, |
| 1064 | minMatchCharLength = Config.minMatchCharLength, |
| 1065 | isCaseSensitive = Config.isCaseSensitive, |
| 1066 | ignoreLocation = Config.ignoreLocation |
| 1067 | } = {} |
| 1068 | ) { |
| 1069 | super(pattern); |
| 1070 | this._bitapSearch = new BitapSearch(pattern, { |
| 1071 | location, |
| 1072 | threshold, |
| 1073 | distance, |
| 1074 | includeMatches, |
| 1075 | findAllMatches, |
| 1076 | minMatchCharLength, |
| 1077 | isCaseSensitive, |
| 1078 | ignoreLocation |
| 1079 | }); |
| 1080 | } |
| 1081 | static get type() { |
| 1082 | return 'fuzzy' |
| 1083 | } |
| 1084 | static get multiRegex() { |
| 1085 | return /^"(.*)"$/ |
| 1086 | } |
| 1087 | static get singleRegex() { |
| 1088 | return /^(.*)$/ |
| 1089 | } |
| 1090 | search(text) { |
| 1091 | return this._bitapSearch.searchIn(text) |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // Token: 'file |
| 1096 | |
| 1097 | class IncludeMatch extends BaseMatch { |
| 1098 | constructor(pattern) { |
| 1099 | super(pattern); |
| 1100 | } |
| 1101 | static get type() { |
| 1102 | return 'include' |
| 1103 | } |
| 1104 | static get multiRegex() { |
| 1105 | return /^'"(.*)"$/ |
| 1106 | } |
| 1107 | static get singleRegex() { |
| 1108 | return /^'(.*)$/ |
| 1109 | } |
| 1110 | search(text) { |
| 1111 | let location = 0; |
| 1112 | let index; |
| 1113 | |
| 1114 | const indices = []; |
| 1115 | const patternLen = this.pattern.length; |
| 1116 | |
| 1117 | // Get all exact matches |
| 1118 | while ((index = text.indexOf(this.pattern, location)) > -1) { |
| 1119 | location = index + patternLen; |
| 1120 | indices.push([index, location - 1]); |
| 1121 | } |
| 1122 | |
| 1123 | const isMatch = !!indices.length; |
| 1124 | |
| 1125 | return { |
| 1126 | isMatch, |
| 1127 | score: isMatch ? 0 : 1, |
| 1128 | indices |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | // ❗Order is important. DO NOT CHANGE. |
| 1134 | const searchers = [ |
| 1135 | ExactMatch, |
| 1136 | IncludeMatch, |
| 1137 | PrefixExactMatch, |
| 1138 | InversePrefixExactMatch, |
| 1139 | InverseSuffixExactMatch, |
| 1140 | SuffixExactMatch, |
| 1141 | InverseExactMatch, |
| 1142 | FuzzyMatch |
| 1143 | ]; |
| 1144 | |
| 1145 | const searchersLen = searchers.length; |
| 1146 | |
| 1147 | // Regex to split by spaces, but keep anything in quotes together |
| 1148 | const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/; |
| 1149 | const OR_TOKEN = '|'; |
| 1150 | |
| 1151 | // Return a 2D array representation of the query, for simpler parsing. |
| 1152 | // Example: |
| 1153 | // "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]] |
| 1154 | function parseQuery(pattern, options = {}) { |
| 1155 | return pattern.split(OR_TOKEN).map((item) => { |
| 1156 | let query = item |
| 1157 | .trim() |
| 1158 | .split(SPACE_RE) |
| 1159 | .filter((item) => item && !!item.trim()); |
| 1160 | |
| 1161 | let results = []; |
| 1162 | for (let i = 0, len = query.length; i < len; i += 1) { |
| 1163 | const queryItem = query[i]; |
| 1164 | |
| 1165 | // 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`) |
| 1166 | let found = false; |
| 1167 | let idx = -1; |
| 1168 | while (!found && ++idx < searchersLen) { |
| 1169 | const searcher = searchers[idx]; |
| 1170 | let token = searcher.isMultiMatch(queryItem); |
| 1171 | if (token) { |
| 1172 | results.push(new searcher(token, options)); |
| 1173 | found = true; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | if (found) { |
| 1178 | continue |
| 1179 | } |
| 1180 | |
| 1181 | // 2. Handle single query matches (i.e, once that are *not* quoted) |
| 1182 | idx = -1; |
| 1183 | while (++idx < searchersLen) { |
| 1184 | const searcher = searchers[idx]; |
| 1185 | let token = searcher.isSingleMatch(queryItem); |
| 1186 | if (token) { |
| 1187 | results.push(new searcher(token, options)); |
| 1188 | break |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | return results |
| 1194 | }) |
| 1195 | } |
| 1196 | |
| 1197 | // These extended matchers can return an array of matches, as opposed |
| 1198 | // to a singl match |
| 1199 | const MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]); |
| 1200 | |
| 1201 | /** |
| 1202 | * Command-like searching |
| 1203 | * ====================== |
| 1204 | * |
| 1205 | * Given multiple search terms delimited by spaces.e.g. `^jscript .python$ ruby !java`, |
| 1206 | * search in a given text. |
| 1207 | * |
| 1208 | * Search syntax: |
| 1209 | * |
| 1210 | * | Token | Match type | Description | |
| 1211 | * | ----------- | -------------------------- | -------------------------------------- | |
| 1212 | * | `jscript` | fuzzy-match | Items that fuzzy match `jscript` | |
| 1213 | * | `=scheme` | exact-match | Items that are `scheme` | |
| 1214 | * | `'python` | include-match | Items that include `python` | |
| 1215 | * | `!ruby` | inverse-exact-match | Items that do not include `ruby` | |
| 1216 | * | `^java` | prefix-exact-match | Items that start with `java` | |
| 1217 | * | `!^earlang` | inverse-prefix-exact-match | Items that do not start with `earlang` | |
| 1218 | * | `.js$` | suffix-exact-match | Items that end with `.js` | |
| 1219 | * | `!.go$` | inverse-suffix-exact-match | Items that do not end with `.go` | |
| 1220 | * |
| 1221 | * A single pipe character acts as an OR operator. For example, the following |
| 1222 | * query matches entries that start with `core` and end with either`go`, `rb`, |
| 1223 | * or`py`. |
| 1224 | * |
| 1225 | * ``` |
| 1226 | * ^core go$ | rb$ | py$ |
| 1227 | * ``` |
| 1228 | */ |
| 1229 | class ExtendedSearch { |
| 1230 | constructor( |
| 1231 | pattern, |
| 1232 | { |
| 1233 | isCaseSensitive = Config.isCaseSensitive, |
| 1234 | includeMatches = Config.includeMatches, |
| 1235 | minMatchCharLength = Config.minMatchCharLength, |
| 1236 | ignoreLocation = Config.ignoreLocation, |
| 1237 | findAllMatches = Config.findAllMatches, |
| 1238 | location = Config.location, |
| 1239 | threshold = Config.threshold, |
| 1240 | distance = Config.distance |
| 1241 | } = {} |
| 1242 | ) { |
| 1243 | this.query = null; |
| 1244 | this.options = { |
| 1245 | isCaseSensitive, |
| 1246 | includeMatches, |
| 1247 | minMatchCharLength, |
| 1248 | findAllMatches, |
| 1249 | ignoreLocation, |
| 1250 | location, |
| 1251 | threshold, |
| 1252 | distance |
| 1253 | }; |
| 1254 | |
| 1255 | this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); |
| 1256 | this.query = parseQuery(this.pattern, this.options); |
| 1257 | } |
| 1258 | |
| 1259 | static condition(_, options) { |
| 1260 | return options.useExtendedSearch |
| 1261 | } |
| 1262 | |
| 1263 | searchIn(text) { |
| 1264 | const query = this.query; |
| 1265 | |
| 1266 | if (!query) { |
| 1267 | return { |
| 1268 | isMatch: false, |
| 1269 | score: 1 |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | const { includeMatches, isCaseSensitive } = this.options; |
| 1274 | |
| 1275 | text = isCaseSensitive ? text : text.toLowerCase(); |
| 1276 | |
| 1277 | let numMatches = 0; |
| 1278 | let allIndices = []; |
| 1279 | let totalScore = 0; |
| 1280 | |
| 1281 | // ORs |
| 1282 | for (let i = 0, qLen = query.length; i < qLen; i += 1) { |
| 1283 | const searchers = query[i]; |
| 1284 | |
| 1285 | // Reset indices |
| 1286 | allIndices.length = 0; |
| 1287 | numMatches = 0; |
| 1288 | |
| 1289 | // ANDs |
| 1290 | for (let j = 0, pLen = searchers.length; j < pLen; j += 1) { |
| 1291 | const searcher = searchers[j]; |
| 1292 | const { isMatch, indices, score } = searcher.search(text); |
| 1293 | |
| 1294 | if (isMatch) { |
| 1295 | numMatches += 1; |
| 1296 | totalScore += score; |
| 1297 | if (includeMatches) { |
| 1298 | const type = searcher.constructor.type; |
| 1299 | if (MultiMatchSet.has(type)) { |
| 1300 | allIndices = [...allIndices, ...indices]; |
| 1301 | } else { |
| 1302 | allIndices.push(indices); |
| 1303 | } |
| 1304 | } |
| 1305 | } else { |
| 1306 | totalScore = 0; |
| 1307 | numMatches = 0; |
| 1308 | allIndices.length = 0; |
| 1309 | break |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | // OR condition, so if TRUE, return |
| 1314 | if (numMatches) { |
| 1315 | let result = { |
| 1316 | isMatch: true, |
| 1317 | score: totalScore / numMatches |
| 1318 | }; |
| 1319 | |
| 1320 | if (includeMatches) { |
| 1321 | result.indices = allIndices; |
| 1322 | } |
| 1323 | |
| 1324 | return result |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | // Nothing was matched |
| 1329 | return { |
| 1330 | isMatch: false, |
| 1331 | score: 1 |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | const registeredSearchers = []; |
| 1337 | |
| 1338 | function register(...args) { |
| 1339 | registeredSearchers.push(...args); |
| 1340 | } |
| 1341 | |
| 1342 | function createSearcher(pattern, options) { |
| 1343 | for (let i = 0, len = registeredSearchers.length; i < len; i += 1) { |
| 1344 | let searcherClass = registeredSearchers[i]; |
| 1345 | if (searcherClass.condition(pattern, options)) { |
| 1346 | return new searcherClass(pattern, options) |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | return new BitapSearch(pattern, options) |
| 1351 | } |
| 1352 | |
| 1353 | const LogicalOperator = { |
| 1354 | AND: '$and', |
| 1355 | OR: '$or' |
| 1356 | }; |
| 1357 | |
| 1358 | const KeyType = { |
| 1359 | PATH: '$path', |
| 1360 | PATTERN: '$val' |
| 1361 | }; |
| 1362 | |
| 1363 | const isExpression = (query) => |
| 1364 | !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]); |
| 1365 | |
| 1366 | const isPath = (query) => !!query[KeyType.PATH]; |
| 1367 | |
| 1368 | const isLeaf = (query) => |
| 1369 | !isArray(query) && isObject(query) && !isExpression(query); |
| 1370 | |
| 1371 | const convertToExplicit = (query) => ({ |
| 1372 | [LogicalOperator.AND]: Object.keys(query).map((key) => ({ |
| 1373 | [key]: query[key] |
| 1374 | })) |
| 1375 | }); |
| 1376 | |
| 1377 | // When `auto` is `true`, the parse function will infer and initialize and add |
| 1378 | // the appropriate `Searcher` instance |
| 1379 | function parse(query, options, { auto = true } = {}) { |
| 1380 | const next = (query) => { |
| 1381 | let keys = Object.keys(query); |
| 1382 | |
| 1383 | const isQueryPath = isPath(query); |
| 1384 | |
| 1385 | if (!isQueryPath && keys.length > 1 && !isExpression(query)) { |
| 1386 | return next(convertToExplicit(query)) |
| 1387 | } |
| 1388 | |
| 1389 | if (isLeaf(query)) { |
| 1390 | const key = isQueryPath ? query[KeyType.PATH] : keys[0]; |
| 1391 | |
| 1392 | const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key]; |
| 1393 | |
| 1394 | if (!isString(pattern)) { |
| 1395 | throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key)) |
| 1396 | } |
| 1397 | |
| 1398 | const obj = { |
| 1399 | keyId: createKeyId(key), |
| 1400 | pattern |
| 1401 | }; |
| 1402 | |
| 1403 | if (auto) { |
| 1404 | obj.searcher = createSearcher(pattern, options); |
| 1405 | } |
| 1406 | |
| 1407 | return obj |
| 1408 | } |
| 1409 | |
| 1410 | let node = { |
| 1411 | children: [], |
| 1412 | operator: keys[0] |
| 1413 | }; |
| 1414 | |
| 1415 | keys.forEach((key) => { |
| 1416 | const value = query[key]; |
| 1417 | |
| 1418 | if (isArray(value)) { |
| 1419 | value.forEach((item) => { |
| 1420 | node.children.push(next(item)); |
| 1421 | }); |
| 1422 | } |
| 1423 | }); |
| 1424 | |
| 1425 | return node |
| 1426 | }; |
| 1427 | |
| 1428 | if (!isExpression(query)) { |
| 1429 | query = convertToExplicit(query); |
| 1430 | } |
| 1431 | |
| 1432 | return next(query) |
| 1433 | } |
| 1434 | |
| 1435 | // Practical scoring function |
| 1436 | function computeScore( |
| 1437 | results, |
| 1438 | { ignoreFieldNorm = Config.ignoreFieldNorm } |
| 1439 | ) { |
| 1440 | results.forEach((result) => { |
| 1441 | let totalScore = 1; |
| 1442 | |
| 1443 | result.matches.forEach(({ key, norm, score }) => { |
| 1444 | const weight = key ? key.weight : null; |
| 1445 | |
| 1446 | totalScore *= Math.pow( |
| 1447 | score === 0 && weight ? Number.EPSILON : score, |
| 1448 | (weight || 1) * (ignoreFieldNorm ? 1 : norm) |
| 1449 | ); |
| 1450 | }); |
| 1451 | |
| 1452 | result.score = totalScore; |
| 1453 | }); |
| 1454 | } |
| 1455 | |
| 1456 | function transformMatches(result, data) { |
| 1457 | const matches = result.matches; |
| 1458 | data.matches = []; |
| 1459 | |
| 1460 | if (!isDefined(matches)) { |
| 1461 | return |
| 1462 | } |
| 1463 | |
| 1464 | matches.forEach((match) => { |
| 1465 | if (!isDefined(match.indices) || !match.indices.length) { |
| 1466 | return |
| 1467 | } |
| 1468 | |
| 1469 | const { indices, value } = match; |
| 1470 | |
| 1471 | let obj = { |
| 1472 | indices, |
| 1473 | value |
| 1474 | }; |
| 1475 | |
| 1476 | if (match.key) { |
| 1477 | obj.key = match.key.src; |
| 1478 | } |
| 1479 | |
| 1480 | if (match.idx > -1) { |
| 1481 | obj.refIndex = match.idx; |
| 1482 | } |
| 1483 | |
| 1484 | data.matches.push(obj); |
| 1485 | }); |
| 1486 | } |
| 1487 | |
| 1488 | function transformScore(result, data) { |
| 1489 | data.score = result.score; |
| 1490 | } |
| 1491 | |
| 1492 | function format( |
| 1493 | results, |
| 1494 | docs, |
| 1495 | { |
| 1496 | includeMatches = Config.includeMatches, |
| 1497 | includeScore = Config.includeScore |
| 1498 | } = {} |
| 1499 | ) { |
| 1500 | const transformers = []; |
| 1501 | |
| 1502 | if (includeMatches) transformers.push(transformMatches); |
| 1503 | if (includeScore) transformers.push(transformScore); |
| 1504 | |
| 1505 | return results.map((result) => { |
| 1506 | const { idx } = result; |
| 1507 | |
| 1508 | const data = { |
| 1509 | item: docs[idx], |
| 1510 | refIndex: idx |
| 1511 | }; |
| 1512 | |
| 1513 | if (transformers.length) { |
| 1514 | transformers.forEach((transformer) => { |
| 1515 | transformer(result, data); |
| 1516 | }); |
| 1517 | } |
| 1518 | |
| 1519 | return data |
| 1520 | }) |
| 1521 | } |
| 1522 | |
| 1523 | class Fuse { |
| 1524 | constructor(docs, options = {}, index) { |
| 1525 | this.options = { ...Config, ...options }; |
| 1526 | |
| 1527 | if ( |
| 1528 | this.options.useExtendedSearch && |
| 1529 | !true |
| 1530 | ) { |
| 1531 | throw new Error(EXTENDED_SEARCH_UNAVAILABLE) |
| 1532 | } |
| 1533 | |
| 1534 | this._keyStore = new KeyStore(this.options.keys); |
| 1535 | |
| 1536 | this.setCollection(docs, index); |
| 1537 | } |
| 1538 | |
| 1539 | setCollection(docs, index) { |
| 1540 | this._docs = docs; |
| 1541 | |
| 1542 | if (index && !(index instanceof FuseIndex)) { |
| 1543 | throw new Error(INCORRECT_INDEX_TYPE) |
| 1544 | } |
| 1545 | |
| 1546 | this._myIndex = |
| 1547 | index || |
| 1548 | createIndex(this.options.keys, this._docs, { |
| 1549 | getFn: this.options.getFn, |
| 1550 | fieldNormWeight: this.options.fieldNormWeight |
| 1551 | }); |
| 1552 | } |
| 1553 | |
| 1554 | add(doc) { |
| 1555 | if (!isDefined(doc)) { |
| 1556 | return |
| 1557 | } |
| 1558 | |
| 1559 | this._docs.push(doc); |
| 1560 | this._myIndex.add(doc); |
| 1561 | } |
| 1562 | |
| 1563 | remove(predicate = (/* doc, idx */) => false) { |
| 1564 | const results = []; |
| 1565 | |
| 1566 | for (let i = 0, len = this._docs.length; i < len; i += 1) { |
| 1567 | const doc = this._docs[i]; |
| 1568 | if (predicate(doc, i)) { |
| 1569 | this.removeAt(i); |
| 1570 | i -= 1; |
| 1571 | len -= 1; |
| 1572 | |
| 1573 | results.push(doc); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | return results |
| 1578 | } |
| 1579 | |
| 1580 | removeAt(idx) { |
| 1581 | this._docs.splice(idx, 1); |
| 1582 | this._myIndex.removeAt(idx); |
| 1583 | } |
| 1584 | |
| 1585 | getIndex() { |
| 1586 | return this._myIndex |
| 1587 | } |
| 1588 | |
| 1589 | search(query, { limit = -1 } = {}) { |
| 1590 | const { |
| 1591 | includeMatches, |
| 1592 | includeScore, |
| 1593 | shouldSort, |
| 1594 | sortFn, |
| 1595 | ignoreFieldNorm |
| 1596 | } = this.options; |
| 1597 | |
| 1598 | let results = isString(query) |
| 1599 | ? isString(this._docs[0]) |
| 1600 | ? this._searchStringList(query) |
| 1601 | : this._searchObjectList(query) |
| 1602 | : this._searchLogical(query); |
| 1603 | |
| 1604 | computeScore(results, { ignoreFieldNorm }); |
| 1605 | |
| 1606 | if (shouldSort) { |
| 1607 | results.sort(sortFn); |
| 1608 | } |
| 1609 | |
| 1610 | if (isNumber(limit) && limit > -1) { |
| 1611 | results = results.slice(0, limit); |
| 1612 | } |
| 1613 | |
| 1614 | return format(results, this._docs, { |
| 1615 | includeMatches, |
| 1616 | includeScore |
| 1617 | }) |
| 1618 | } |
| 1619 | |
| 1620 | _searchStringList(query) { |
| 1621 | const searcher = createSearcher(query, this.options); |
| 1622 | const { records } = this._myIndex; |
| 1623 | const results = []; |
| 1624 | |
| 1625 | // Iterate over every string in the index |
| 1626 | records.forEach(({ v: text, i: idx, n: norm }) => { |
| 1627 | if (!isDefined(text)) { |
| 1628 | return |
| 1629 | } |
| 1630 | |
| 1631 | const { isMatch, score, indices } = searcher.searchIn(text); |
| 1632 | |
| 1633 | if (isMatch) { |
| 1634 | results.push({ |
| 1635 | item: text, |
| 1636 | idx, |
| 1637 | matches: [{ score, value: text, norm, indices }] |
| 1638 | }); |
| 1639 | } |
| 1640 | }); |
| 1641 | |
| 1642 | return results |
| 1643 | } |
| 1644 | |
| 1645 | _searchLogical(query) { |
| 1646 | |
| 1647 | const expression = parse(query, this.options); |
| 1648 | |
| 1649 | const evaluate = (node, item, idx) => { |
| 1650 | if (!node.children) { |
| 1651 | const { keyId, searcher } = node; |
| 1652 | |
| 1653 | const matches = this._findMatches({ |
| 1654 | key: this._keyStore.get(keyId), |
| 1655 | value: this._myIndex.getValueForItemAtKeyId(item, keyId), |
| 1656 | searcher |
| 1657 | }); |
| 1658 | |
| 1659 | if (matches && matches.length) { |
| 1660 | return [ |
| 1661 | { |
| 1662 | idx, |
| 1663 | item, |
| 1664 | matches |
| 1665 | } |
| 1666 | ] |
| 1667 | } |
| 1668 | |
| 1669 | return [] |
| 1670 | } |
| 1671 | |
| 1672 | const res = []; |
| 1673 | for (let i = 0, len = node.children.length; i < len; i += 1) { |
| 1674 | const child = node.children[i]; |
| 1675 | const result = evaluate(child, item, idx); |
| 1676 | if (result.length) { |
| 1677 | res.push(...result); |
| 1678 | } else if (node.operator === LogicalOperator.AND) { |
| 1679 | return [] |
| 1680 | } |
| 1681 | } |
| 1682 | return res |
| 1683 | }; |
| 1684 | |
| 1685 | const records = this._myIndex.records; |
| 1686 | const resultMap = {}; |
| 1687 | const results = []; |
| 1688 | |
| 1689 | records.forEach(({ $: item, i: idx }) => { |
| 1690 | if (isDefined(item)) { |
| 1691 | let expResults = evaluate(expression, item, idx); |
| 1692 | |
| 1693 | if (expResults.length) { |
| 1694 | // Dedupe when adding |
| 1695 | if (!resultMap[idx]) { |
| 1696 | resultMap[idx] = { idx, item, matches: [] }; |
| 1697 | results.push(resultMap[idx]); |
| 1698 | } |
| 1699 | expResults.forEach(({ matches }) => { |
| 1700 | resultMap[idx].matches.push(...matches); |
| 1701 | }); |
| 1702 | } |
| 1703 | } |
| 1704 | }); |
| 1705 | |
| 1706 | return results |
| 1707 | } |
| 1708 | |
| 1709 | _searchObjectList(query) { |
| 1710 | const searcher = createSearcher(query, this.options); |
| 1711 | const { keys, records } = this._myIndex; |
| 1712 | const results = []; |
| 1713 | |
| 1714 | // List is Array<Object> |
| 1715 | records.forEach(({ $: item, i: idx }) => { |
| 1716 | if (!isDefined(item)) { |
| 1717 | return |
| 1718 | } |
| 1719 | |
| 1720 | let matches = []; |
| 1721 | |
| 1722 | // Iterate over every key (i.e, path), and fetch the value at that key |
| 1723 | keys.forEach((key, keyIndex) => { |
| 1724 | matches.push( |
| 1725 | ...this._findMatches({ |
| 1726 | key, |
| 1727 | value: item[keyIndex], |
| 1728 | searcher |
| 1729 | }) |
| 1730 | ); |
| 1731 | }); |
| 1732 | |
| 1733 | if (matches.length) { |
| 1734 | results.push({ |
| 1735 | idx, |
| 1736 | item, |
| 1737 | matches |
| 1738 | }); |
| 1739 | } |
| 1740 | }); |
| 1741 | |
| 1742 | return results |
| 1743 | } |
| 1744 | _findMatches({ key, value, searcher }) { |
| 1745 | if (!isDefined(value)) { |
| 1746 | return [] |
| 1747 | } |
| 1748 | |
| 1749 | let matches = []; |
| 1750 | |
| 1751 | if (isArray(value)) { |
| 1752 | value.forEach(({ v: text, i: idx, n: norm }) => { |
| 1753 | if (!isDefined(text)) { |
| 1754 | return |
| 1755 | } |
| 1756 | |
| 1757 | const { isMatch, score, indices } = searcher.searchIn(text); |
| 1758 | |
| 1759 | if (isMatch) { |
| 1760 | matches.push({ |
| 1761 | score, |
| 1762 | key, |
| 1763 | value: text, |
| 1764 | idx, |
| 1765 | norm, |
| 1766 | indices |
| 1767 | }); |
| 1768 | } |
| 1769 | }); |
| 1770 | } else { |
| 1771 | const { v: text, n: norm } = value; |
| 1772 | |
| 1773 | const { isMatch, score, indices } = searcher.searchIn(text); |
| 1774 | |
| 1775 | if (isMatch) { |
| 1776 | matches.push({ score, key, value: text, norm, indices }); |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | return matches |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | Fuse.version = '6.6.2'; |
| 1785 | Fuse.createIndex = createIndex; |
| 1786 | Fuse.parseIndex = parseIndex; |
| 1787 | Fuse.config = Config; |
| 1788 | |
| 1789 | { |
| 1790 | Fuse.parseQuery = parse; |
| 1791 | } |
| 1792 | |
| 1793 | { |
| 1794 | register(ExtendedSearch); |
| 1795 | } |
| 1796 | |
| 1797 | const scSelectCss = ":host{display:block;--focus-ring:0 0 0 var(--sc-focus-ring-width) var(--sc-focus-ring-color-primary)}.search{margin:var(--sc-spacing-x-small) var(--sc-spacing-x-small) 0 var(--sc-spacing-x-small)}.loading{text-align:center;margin:var(--sc-spacing-small)}.select{font-family:var(--sc-input-font-family);font-weight:var(--sc-font-weight-normal)}sc-dropdown{display:block}.trigger{overflow:hidden;box-sizing:border-box;width:100%;display:flex;align-items:center;justify-content:space-between;width:100%;border-style:solid;border-width:var(--sc-input-border-width);background-color:var(--sc-select-background-color, var(--sc-color-white));border-color:var(--sc-select-border-color, var(--sc-color-gray-300));color:var(--sc-input-color);text-decoration:none;user-select:none;white-space:nowrap;vertical-align:middle;padding:0;transition:var(--sc-input-transition, var(--sc-transition-medium)) background-color, var(--sc-input-transition, var(--sc-transition-medium)) color, var(--sc-input-transition, var(--sc-transition-medium)) border, var(--sc-input-transition, var(--sc-transition-medium)) box-shadow;cursor:inherit;box-shadow:var(--sc-shadow-small);font-size:var(--sc-button-font-size-medium);min-height:var(--sc-input-height-medium);line-height:calc(var(--sc-input-height-medium) - var(--sc-input-border-width) * 2);border-radius:var(--sc-input-border-radius-medium);padding:0 var(--sc-spacing-small)}.trigger svg{display:block;width:1em;height:1em}.select.select--focused:not(.select--disabled) .trigger{background-color:var(--sc-input-background-color-focus);border-color:var(--sc-input-border-color-focus);box-shadow:var(--focus-ring);z-index:2}.select--disabled{cursor:not-allowed}.select--disabled sc-dropdown{opacity:0.65}.select__value{overflow:hidden;text-overflow:ellipsis}.select__empty{text-align:center;margin:var(--sc-spacing-small);color:var(--sc-color-gray-400)}.select--placeholder .trigger{color:var(--sc-input-placeholder-color)}.select__hidden-input{position:absolute;opacity:0;padding:0px;margin:0px;pointer-events:none;width:0}.select__suffix-description,.select__description{font-size:var(--sc-input-help-text-font-size-medium);opacity:0.65}.select__caret{transition:transform 0.25s ease;line-height:0}.select--is-open .select__caret{transform:rotate(180deg)}.select--squared .trigger{border-radius:0}.select--squared-top .trigger{border-top-left-radius:0;border-top-right-radius:0}.select--squared-bottom .trigger{border-bottom-left-radius:0;border-bottom-right-radius:0}.select--squared-left .trigger{border-top-left-radius:0;border-bottom-left-radius:0}.select--squared-right .trigger{border-top-right-radius:0;border-bottom-right-radius:0}.choice__icon--image{width:18px;height:18px;object-fit:contain}sc-menu-item.is-unavailable{--sc-menu-item-color:var(--sc-color-gray-500)}"; |
| 1798 | const ScSelectStyle0 = scSelectCss; |
| 1799 | |
| 1800 | let id = 0; |
| 1801 | let itemIndex = 0; |
| 1802 | let arrowFlag = ''; |
| 1803 | const ScSelectDropdown = class { |
| 1804 | constructor(hostRef) { |
| 1805 | registerInstance(this, hostRef); |
| 1806 | this.scSearch = createEvent(this, "scSearch", 7); |
| 1807 | this.scOpen = createEvent(this, "scOpen", 7); |
| 1808 | this.scClose = createEvent(this, "scClose", 7); |
| 1809 | this.scBlur = createEvent(this, "scBlur", 7); |
| 1810 | this.scFocus = createEvent(this, "scFocus", 7); |
| 1811 | this.scChange = createEvent(this, "scChange", 7); |
| 1812 | this.scScrollEnd = createEvent(this, "scScrollEnd", 7); |
| 1813 | this.inputId = `select-${++id}`; |
| 1814 | this.helpId = `select-help-text-${id}`; |
| 1815 | this.labelId = `select-label-${id}`; |
| 1816 | this.autocomplete = undefined; |
| 1817 | this.placeholder = ''; |
| 1818 | this.searchPlaceholder = ''; |
| 1819 | this.value = ''; |
| 1820 | this.choices = []; |
| 1821 | this.unselect = true; |
| 1822 | this.required = undefined; |
| 1823 | this.loading = undefined; |
| 1824 | this.search = undefined; |
| 1825 | this.closeOnSelect = true; |
| 1826 | this.name = undefined; |
| 1827 | this.help = undefined; |
| 1828 | this.label = undefined; |
| 1829 | this.size = 'medium'; |
| 1830 | this.position = 'bottom-right'; |
| 1831 | this.placement = 'bottom-start'; |
| 1832 | this.invalid = false; |
| 1833 | this.open = undefined; |
| 1834 | this.disabled = undefined; |
| 1835 | this.showParentLabel = true; |
| 1836 | this.hoist = false; |
| 1837 | this.squared = undefined; |
| 1838 | this.squaredBottom = undefined; |
| 1839 | this.squaredTop = undefined; |
| 1840 | this.squaredLeft = undefined; |
| 1841 | this.squaredRight = undefined; |
| 1842 | this.hasFocus = false; |
| 1843 | this.searchTerm = ''; |
| 1844 | this.filteredChoices = []; |
| 1845 | } |
| 1846 | /** Trigger focus on show */ |
| 1847 | handleShow() { |
| 1848 | this.open = true; |
| 1849 | setTimeout(() => { |
| 1850 | this.searchInput && this.searchInput.triggerFocus(); |
| 1851 | }, 50); |
| 1852 | } |
| 1853 | handleHide() { |
| 1854 | this.open = false; |
| 1855 | itemIndex = 0; |
| 1856 | this.scClose.emit(); |
| 1857 | } |
| 1858 | handleBlur() { |
| 1859 | this.hasFocus = false; |
| 1860 | this.scBlur.emit(); |
| 1861 | } |
| 1862 | handleFocus() { |
| 1863 | this.hasFocus = true; |
| 1864 | this.el.focus(); |
| 1865 | this.scFocus.emit(); |
| 1866 | } |
| 1867 | /** Get the display value of the item. */ |
| 1868 | displayValue() { |
| 1869 | var _a; |
| 1870 | if (!this.value) |
| 1871 | return false; |
| 1872 | let chosen = this.choices.find(choice => choice.value == this.value); |
| 1873 | let append = ''; |
| 1874 | if (!chosen) { |
| 1875 | if (this.showParentLabel) { |
| 1876 | append = (_a = this.choices.find(choice => { var _a, _b; return (_b = (_a = choice === null || choice === void 0 ? void 0 : choice.choices) === null || _a === void 0 ? void 0 : _a.some) === null || _b === void 0 ? void 0 : _b.call(_a, subChoice => subChoice.value === this.value); })) === null || _a === void 0 ? void 0 : _a.label; |
| 1877 | } |
| 1878 | const subchoices = (this.choices || []).map(choice => choice.choices).flat(); |
| 1879 | chosen = subchoices.find(choice => (choice === null || choice === void 0 ? void 0 : choice.value) == this.value); |
| 1880 | } |
| 1881 | if (chosen) { |
| 1882 | return `${append ? append + ' — ' : ''}${chosen === null || chosen === void 0 ? void 0 : chosen.label}`; |
| 1883 | } |
| 1884 | return false; |
| 1885 | } |
| 1886 | isChecked({ value, checked = false }) { |
| 1887 | if (checked) { |
| 1888 | return true; |
| 1889 | } |
| 1890 | return !!value && this.value === value; |
| 1891 | } |
| 1892 | /** Sets a custom validation message. If `message` is not empty, the field will be considered invalid. */ |
| 1893 | async setCustomValidity(message) { |
| 1894 | this.input.setCustomValidity(message); |
| 1895 | this.invalid = !this.input.checkValidity(); |
| 1896 | } |
| 1897 | async reportValidity() { |
| 1898 | return this.input.reportValidity(); |
| 1899 | } |
| 1900 | handleQuery(e) { |
| 1901 | this.searchTerm = e.target.value; |
| 1902 | this.scSearch.emit(this.searchTerm); |
| 1903 | } |
| 1904 | handleSelect(choice) { |
| 1905 | const { value } = choice; |
| 1906 | if (this.value === value && this.unselect) { |
| 1907 | this.value = ''; |
| 1908 | } |
| 1909 | else { |
| 1910 | this.value = value; |
| 1911 | } |
| 1912 | if (this.closeOnSelect) { |
| 1913 | this.searchTerm = ''; |
| 1914 | } |
| 1915 | this.scChange.emit(choice); |
| 1916 | } |
| 1917 | handleSearchChange() { |
| 1918 | const fuse = new Fuse(this.choices, { |
| 1919 | keys: ['value', 'label'], |
| 1920 | }); |
| 1921 | if (this.searchTerm) { |
| 1922 | const results = fuse.search(this.searchTerm); |
| 1923 | this.filteredChoices = results.map(result => result.item); |
| 1924 | } |
| 1925 | else { |
| 1926 | this.filteredChoices = this.choices; |
| 1927 | } |
| 1928 | } |
| 1929 | handleValueChange() { |
| 1930 | if (this.input) { |
| 1931 | this.invalid = !this.input.checkValidity(); |
| 1932 | } |
| 1933 | } |
| 1934 | handleOpenChange() { |
| 1935 | if (this.open) { |
| 1936 | this.scOpen.emit(); |
| 1937 | this.searchInput && this.searchInput.triggerFocus(); |
| 1938 | } |
| 1939 | else { |
| 1940 | this.scClose.emit(); |
| 1941 | } |
| 1942 | } |
| 1943 | handleMenuScroll(e) { |
| 1944 | const scrollTop = e.target.scrollTop; |
| 1945 | const scrollHeight = e.target.scrollHeight; |
| 1946 | const offsetHeight = e.target.offsetHeight; |
| 1947 | const contentHeight = scrollHeight - offsetHeight; |
| 1948 | if (contentHeight - scrollTop < 5) |
| 1949 | this.scScrollEnd.emit(); |
| 1950 | } |
| 1951 | componentWillLoad() { |
| 1952 | this.handleSearchChange(); |
| 1953 | } |
| 1954 | componentDidLoad() { |
| 1955 | this.formController = new FormSubmitController(this.el).addFormData(); |
| 1956 | if (this.open) { |
| 1957 | this.searchInput && this.searchInput.triggerFocus(); |
| 1958 | } |
| 1959 | } |
| 1960 | getItems() { |
| 1961 | return [...this.el.shadowRoot.querySelectorAll('sc-menu-item')]; |
| 1962 | } |
| 1963 | handleKeyDown(event) { |
| 1964 | var _a, _b; |
| 1965 | const target = event.target; |
| 1966 | const items = this.getItems(); |
| 1967 | // Ignore key presses on tags |
| 1968 | if (target.tagName.toLowerCase() === 'sc-tag') { |
| 1969 | return; |
| 1970 | } |
| 1971 | // Tabbing out of the control closes it |
| 1972 | if (event.key === 'Tab') { |
| 1973 | if (this.open) { |
| 1974 | this.handleHide(); |
| 1975 | } |
| 1976 | return; |
| 1977 | } |
| 1978 | // Up/down opens the menu |
| 1979 | if (['ArrowDown', 'ArrowUp'].includes(event.key)) { |
| 1980 | event.preventDefault(); |
| 1981 | // Show the menu if it's not already open |
| 1982 | if (!this.open) { |
| 1983 | this.handleShow(); |
| 1984 | } |
| 1985 | // Focus on a menu item |
| 1986 | if (event.key === 'ArrowDown') { |
| 1987 | if (arrowFlag == 'up') { |
| 1988 | itemIndex = itemIndex + 2; |
| 1989 | } |
| 1990 | if (itemIndex > items.length - 1) { |
| 1991 | itemIndex = 0; |
| 1992 | } |
| 1993 | items[itemIndex].setFocus(); |
| 1994 | arrowFlag = 'down'; |
| 1995 | itemIndex++; |
| 1996 | return; |
| 1997 | } |
| 1998 | if (event.key === 'ArrowUp') { |
| 1999 | if (arrowFlag == 'down') { |
| 2000 | itemIndex = itemIndex - 2; |
| 2001 | } |
| 2002 | if (itemIndex < 0) { |
| 2003 | itemIndex = items.length - 1; |
| 2004 | } |
| 2005 | items[itemIndex].setFocus(); |
| 2006 | arrowFlag = 'up'; |
| 2007 | itemIndex--; |
| 2008 | return; |
| 2009 | } |
| 2010 | } |
| 2011 | // Close select dropdown on Esc/Escape key |
| 2012 | if (event.key === 'Escape') { |
| 2013 | if (this.open) { |
| 2014 | this.input.focus(); |
| 2015 | this.handleHide(); |
| 2016 | } |
| 2017 | return; |
| 2018 | } |
| 2019 | // Open select dropdown with Enter |
| 2020 | if (event.key === 'Enter') { |
| 2021 | if (this.open) { |
| 2022 | (_b = (_a = items[itemIndex - 1]) === null || _a === void 0 ? void 0 : _a.click) === null || _b === void 0 ? void 0 : _b.call(_a); |
| 2023 | this.handleHide(); |
| 2024 | this.input.focus(); |
| 2025 | } |
| 2026 | else { |
| 2027 | this.handleShow(); |
| 2028 | } |
| 2029 | } |
| 2030 | // don't open the menu when a CTRL/Command key is pressed |
| 2031 | if (event.ctrlKey || event.metaKey) { |
| 2032 | return; |
| 2033 | } |
| 2034 | // All other "printable" keys open the menu and initiate type to select |
| 2035 | // TODO: this is closing out the dropdown during typing events. |
| 2036 | // FIX: It must have focus as well. And it fix the random closing issue. |
| 2037 | if (!this.open && this.hasFocus && event.key.length === 1) { |
| 2038 | this.handleShow(); |
| 2039 | } |
| 2040 | } |
| 2041 | disconnectedCallback() { |
| 2042 | var _a; |
| 2043 | (_a = this.formController) === null || _a === void 0 ? void 0 : _a.removeFormData(); |
| 2044 | } |
| 2045 | renderIcon(icon) { |
| 2046 | if (isValidURL(icon)) { |
| 2047 | return h("img", { src: icon, alt: "icon", slot: "prefix", class: "choice__icon--image" }); |
| 2048 | } |
| 2049 | return h("sc-icon", { name: icon, slot: "prefix", class: "choice__icon" }); |
| 2050 | } |
| 2051 | renderItem(choice, index) { |
| 2052 | var _a; |
| 2053 | if ((_a = choice === null || choice === void 0 ? void 0 : choice.choices) === null || _a === void 0 ? void 0 : _a.length) { |
| 2054 | return h("sc-menu-label", { key: index }, choice.label); |
| 2055 | } |
| 2056 | return (h("sc-menu-item", { class: { 'is-unavailable': choice === null || choice === void 0 ? void 0 : choice.unavailable }, key: index, checked: this.isChecked(choice), value: choice === null || choice === void 0 ? void 0 : choice.value, onClick: () => !choice.disabled && this.handleSelect(choice), onKeyDown: event => { |
| 2057 | if ((event.key === 'Enter' || event.key === ' ') && !choice.disabled) { |
| 2058 | event.preventDefault(); |
| 2059 | event.stopImmediatePropagation(); |
| 2060 | this.handleSelect(choice); |
| 2061 | } |
| 2062 | }, disabled: choice.disabled, "aria-label": choice.label, "aria-selected": this.isChecked(choice) ? 'true' : 'false', role: "option" }, choice.label, !!(choice === null || choice === void 0 ? void 0 : choice.description) && h("div", { class: "select__description" }, choice === null || choice === void 0 ? void 0 : choice.description), h("div", { slot: "suffix" }, choice === null || choice === void 0 ? void 0 : |
| 2063 | choice.suffix, " ", !!(choice === null || choice === void 0 ? void 0 : choice.suffixDescription) && h("div", { class: "select__suffix-description" }, choice === null || choice === void 0 ? void 0 : choice.suffixDescription)), !!(choice === null || choice === void 0 ? void 0 : choice.icon) && this.renderIcon(choice.icon))); |
| 2064 | } |
| 2065 | render() { |
| 2066 | var _a; |
| 2067 | return (h("div", { key: 'c82376442f9a0b4ce674e8397fda8ff88fc62a75', part: "base", class: { |
| 2068 | 'select': true, |
| 2069 | 'select--placeholder': !this.value, |
| 2070 | 'select--focused': this.hasFocus, |
| 2071 | 'select--is-open': !!this.open, |
| 2072 | 'select--disabled': this.disabled, |
| 2073 | 'select--has-choices': !!((_a = this === null || this === void 0 ? void 0 : this.choices) === null || _a === void 0 ? void 0 : _a.length), |
| 2074 | 'select--squared': this.squared, |
| 2075 | 'select--squared-bottom': this.squaredBottom, |
| 2076 | 'select--squared-top': this.squaredTop, |
| 2077 | 'select--squared-left': this.squaredLeft, |
| 2078 | 'select--squared-right': this.squaredRight, |
| 2079 | } }, h("sc-form-control", { key: 'a054da42fbbc1a940c100e3e683fef6a81577b0d', exportparts: "label, help-text, form-control", size: this.size, required: this.required, label: this.label, help: this.help, inputId: this.inputId, helpId: this.helpId, labelId: this.labelId, name: this.name }, h("input", { key: '35b004bd438cd31ba015156ac033c988ad017087', class: "select__hidden-input", name: this.name, ref: el => (this.input = el), value: this.value, required: this.required, disabled: this.disabled, "aria-hidden": "true", "aria-label": this.displayValue() || this.label || this.placeholder, onBlur: () => this.handleBlur(), onFocus: () => this.handleFocus() }), h("sc-dropdown", { key: '3093a3f0446a66f2eb1b160d0316a3ef22797242', exportparts: "trigger, panel", disabled: this.disabled, open: this.open, closeOnSelect: this.closeOnSelect, position: this.position, placement: this.placement, hoist: this.hoist, style: { '--panel-width': '100%' }, onScShow: () => this.handleShow(), onScHide: () => this.handleHide(), role: "select", "aria-open": this.open ? 'true' : 'false' }, h("slot", { key: '5f09d9a60853bdca22163aadd4d5b3f804e43b46', name: "trigger", slot: "trigger" }, h("div", { key: '9ad0690187536e6a8d4a266e86a5d10ebc12de56', class: "trigger", role: "button", tabIndex: -1, onFocus: () => this.handleFocus(), onBlur: () => this.handleBlur() }, h("div", { key: '78e8d9b498854c0f1c95a46791893d2637918a21', class: "select__value" }, h("slot", { key: '2d934f783c307a70871c393564c4acf99c5b181a' }, this.displayValue() || this.placeholder || wp.i18n.__('Select...', 'surecart'))), h("sc-icon", { key: 'b8fc77aaa75b3eb546fd626f1db1fa5f4b15b771', exportparts: "base:caret", class: "select__caret", name: "chevron-down" }))), this.search && (h("sc-input", { key: 'f97c552f7b7ae7d74b20d7d91396c84955fcb755', exportparts: "base:search__base, input:search__input, form-control:search__form-control", placeholder: this.searchPlaceholder || wp.i18n.__('Search...', 'surecart'), onScInput: e => this.handleQuery(e), class: "search", clearable: true, part: "search", value: this.searchTerm, ref: el => (this.searchInput = el), "aria-label": wp.i18n.__('Type to search', 'surecart'), onKeyDown: e => e.stopPropagation() }, this.loading && h("sc-spinner", { key: '6cc900fb4694e5be272c9cc2848e28da52235707', exportparts: "base:spinner__base", style: { '--spinner-size': '0.5em' }, slot: "suffix" }))), h("sc-menu", { key: '5fac7a62c9364d6b64c79e479f3973d6cd9c98a2', style: { maxHeight: '210px', overflow: 'auto' }, exportparts: "base:menu__base", onScroll: e => this.handleMenuScroll(e), "aria-multiselectable": "false" }, h("slot", { key: '1372af914bb93d11cdd32c25e60c9b7062b559d4', name: "prefix" }), (this.filteredChoices || []).map((choice, index) => { |
| 2080 | return [this.renderItem(choice, index), (choice.choices || []).map(choice => this.renderItem(choice, index))]; |
| 2081 | }), this.loading && (h("div", { key: 'dc0058e82499ff4467979ecb52e2d243445fd641', class: "loading" }, h("sc-spinner", { key: '7a89645fa082a4f9ec8ba0525a7c134a6cdc53b0', exportparts: "base:spinner__base" }))), !this.loading && !this.filteredChoices.length && (h("div", { key: 'ba357fe8276e284df9095400b19aaf35b5c53491', class: "select__empty", part: "empty" }, wp.i18n.__('Nothing Found', 'surecart'))), h("slot", { key: 'd5dd417c7bcd7e805d49951e4e069ff320555a34', name: "suffix" })))))); |
| 2082 | } |
| 2083 | get el() { return getElement(this); } |
| 2084 | static get watchers() { return { |
| 2085 | "searchTerm": ["handleSearchChange"], |
| 2086 | "choices": ["handleSearchChange"], |
| 2087 | "value": ["handleValueChange"], |
| 2088 | "open": ["handleOpenChange"] |
| 2089 | }; } |
| 2090 | }; |
| 2091 | ScSelectDropdown.style = ScSelectStyle0; |
| 2092 | |
| 2093 | export { ScMenuLabel as sc_menu_label, ScSelectDropdown as sc_select }; |
| 2094 | |
| 2095 | //# sourceMappingURL=sc-menu-label_2.entry.js.map |