@asteby/metacore-runtime-react 53.25.0 → 53.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/action-modal-dispatcher.d.ts +3 -3
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +36 -31
- package/dist/action-priority.d.ts +1 -1
- package/dist/activity-diff.d.ts +1 -1
- package/dist/activity-diff.js +1 -1
- package/dist/activity-timeline.d.ts +2 -2
- package/dist/activity-timeline.js +3 -3
- package/dist/activity-value-renderer.d.ts +1 -1
- package/dist/activity-value-renderer.js +3 -3
- package/dist/addon-loader.d.ts +1 -1
- package/dist/addon-loader.js +3 -3
- package/dist/addon-page-host.js +1 -1
- package/dist/addon-page-loader.d.ts +2 -2
- package/dist/addon-page-loader.js +3 -3
- package/dist/api-context.js +4 -4
- package/dist/approval-gate.d.ts +1 -1
- package/dist/approval-gate.js +5 -5
- package/dist/assist-interview.d.ts +1 -1
- package/dist/assist-interview.js +1 -1
- package/dist/attention/index.d.ts +3 -3
- package/dist/attention/index.js +3 -3
- package/dist/attention/use-nav-badges.js +2 -2
- package/dist/attribute-classes.d.ts +1 -1
- package/dist/audit-info.d.ts +1 -1
- package/dist/audit-info.js +5 -5
- package/dist/bulk-image-dialog.d.ts +1 -1
- package/dist/bulk-image-dialog.js +5 -5
- package/dist/bulk-image-import.d.ts +2 -2
- package/dist/bulk-image-import.js +1 -1
- package/dist/bulk-image-target.d.ts +1 -1
- package/dist/bulk-image-target.js +1 -1
- package/dist/bulk-image-wizard.d.ts +1 -1
- package/dist/bulk-image-wizard.js +5 -5
- package/dist/business/catalog-product-search.d.ts +1 -1
- package/dist/business/customer-picker.js +4 -4
- package/dist/business/document-editor-model.d.ts +3 -3
- package/dist/business/document-editor-model.js +4 -4
- package/dist/business/document-editor-panels.d.ts +3 -3
- package/dist/business/document-editor-panels.js +1 -1
- package/dist/business/document-editor.d.ts +2 -2
- package/dist/business/document-editor.js +22 -22
- package/dist/business/document-lines.d.ts +2 -2
- package/dist/business/document-lines.js +3 -3
- package/dist/business/field-errors.d.ts +1 -1
- package/dist/business/field-errors.js +1 -1
- package/dist/business/format.js +1 -1
- package/dist/business/index.d.ts +29 -29
- package/dist/business/index.js +29 -29
- package/dist/business/inspection-checklist.d.ts +1 -1
- package/dist/business/inspection-checklist.js +2 -2
- package/dist/business/inspection.d.ts +1 -1
- package/dist/business/inspection.js +2 -2
- package/dist/business/line-items-editor.d.ts +3 -3
- package/dist/business/line-items-editor.js +5 -5
- package/dist/business/line-items.d.ts +1 -1
- package/dist/business/line-items.js +2 -2
- package/dist/business/line-product-cell.d.ts +2 -2
- package/dist/business/line-product-cell.js +2 -2
- package/dist/business/payment-allocator.d.ts +1 -1
- package/dist/business/payment-allocator.js +2 -2
- package/dist/business/payment-capture.d.ts +1 -1
- package/dist/business/payment-capture.js +3 -3
- package/dist/business/payment.js +1 -1
- package/dist/business/print-send-dialog.js +1 -1
- package/dist/business/product-display.d.ts +1 -1
- package/dist/business/product-options.d.ts +1 -1
- package/dist/business/product-options.js +4 -4
- package/dist/business/product-picker.d.ts +1 -1
- package/dist/business/product-picker.js +3 -3
- package/dist/business/product-search.d.ts +2 -2
- package/dist/business/product-search.js +1 -1
- package/dist/business/refund-destination.d.ts +1 -1
- package/dist/business/refund-destination.js +2 -2
- package/dist/business/refund.js +1 -1
- package/dist/business/relate-documents.js +1 -1
- package/dist/business/return-wizard.d.ts +2 -2
- package/dist/business/return-wizard.js +4 -4
- package/dist/business/return.d.ts +2 -2
- package/dist/business/return.js +2 -2
- package/dist/business/vehicle-picker.js +3 -3
- package/dist/cache-coherence.js +3 -3
- package/dist/capability-providers/index.d.ts +3 -3
- package/dist/capability-providers/index.js +3 -3
- package/dist/capability-providers/provider-sortable-list.d.ts +1 -1
- package/dist/capability-providers/provider-sortable-list.js +1 -1
- package/dist/collection-cell.js +1 -1
- package/dist/column-filter-field.d.ts +1 -1
- package/dist/column-visibility.d.ts +1 -1
- package/dist/custom-stages.d.ts +2 -2
- package/dist/custom-stages.js +1 -1
- package/dist/dashboard-grid.d.ts +1 -1
- package/dist/dashboard-grid.js +3 -3
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.js +1 -1
- package/dist/dialogs/dynamic-record.d.ts +15 -5
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +47 -41
- package/dist/dialogs/export.d.ts +1 -1
- package/dist/dialogs/export.js +2 -2
- package/dist/dialogs/import.d.ts +1 -1
- package/dist/dialogs/import.js +3 -3
- package/dist/dialogs/inline-relation-rows.d.ts +3 -3
- package/dist/dialogs/inline-relation-rows.js +3 -3
- package/dist/dialogs/inline-relations.d.ts +3 -3
- package/dist/dialogs/inline-relations.js +3 -3
- package/dist/dialogs/normalize-submit.d.ts +1 -1
- package/dist/dialogs/normalize-submit.js +3 -3
- package/dist/dialogs/use-inline-relations.d.ts +1 -1
- package/dist/dialogs/use-inline-relations.js +3 -3
- package/dist/dialogs/view-record-dialog.d.ts +1 -1
- package/dist/dialogs/view-record-dialog.js +1 -1
- package/dist/display-value.js +1 -1
- package/dist/document/action-bar.d.ts +1 -1
- package/dist/document/action-bar.js +1 -1
- package/dist/document/document-header.d.ts +2 -2
- package/dist/document/document-header.js +2 -2
- package/dist/document/document-page.d.ts +3 -3
- package/dist/document/document-page.js +9 -9
- package/dist/document/document-timeline.d.ts +2 -2
- package/dist/document/document-timeline.js +2 -2
- package/dist/document/evaluate.d.ts +1 -1
- package/dist/document/evaluate.js +1 -1
- package/dist/document/format.d.ts +1 -1
- package/dist/document/index.d.ts +13 -13
- package/dist/document/index.js +13 -13
- package/dist/document/registry.d.ts +1 -1
- package/dist/document/secondary-bar.js +2 -2
- package/dist/document/smart-buttons.js +1 -1
- package/dist/document/status-badge.d.ts +1 -1
- package/dist/document/use-document-sources.d.ts +1 -1
- package/dist/document/use-document-sources.js +2 -2
- package/dist/document-form-dialog.d.ts +2 -2
- package/dist/document-form-dialog.js +16 -16
- package/dist/document-template-editor.js +1 -1
- package/dist/dynamic-columns-shim.d.ts +1 -1
- package/dist/dynamic-columns.d.ts +3 -3
- package/dist/dynamic-columns.js +19 -19
- package/dist/dynamic-crud-page.d.ts +2 -2
- package/dist/dynamic-crud-page.js +13 -13
- package/dist/dynamic-date-field.d.ts +1 -1
- package/dist/dynamic-date-field.js +1 -1
- package/dist/dynamic-form-schema.d.ts +2 -2
- package/dist/dynamic-form-schema.js +4 -4
- package/dist/dynamic-form.d.ts +10 -10
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +31 -24
- package/dist/dynamic-icon.js +1 -1
- package/dist/dynamic-kanban.d.ts +3 -3
- package/dist/dynamic-kanban.js +25 -25
- package/dist/dynamic-line-items.d.ts +1 -1
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +11 -6
- package/dist/dynamic-multi-select-field.d.ts +1 -1
- package/dist/dynamic-multi-select-field.d.ts.map +1 -1
- package/dist/dynamic-multi-select-field.js +12 -12
- package/dist/dynamic-relation-helpers.d.ts +1 -1
- package/dist/dynamic-relation-helpers.js +2 -2
- package/dist/dynamic-relation.d.ts +2 -2
- package/dist/dynamic-relation.js +15 -15
- package/dist/dynamic-relations.d.ts +2 -2
- package/dist/dynamic-relations.js +1 -1
- package/dist/dynamic-row-actions.d.ts +1 -1
- package/dist/dynamic-row-actions.js +5 -5
- package/dist/dynamic-select-field.d.ts +3 -3
- package/dist/dynamic-select-field.js +11 -11
- package/dist/dynamic-table.d.ts +2 -2
- package/dist/dynamic-table.js +24 -24
- package/dist/dynamic-view.d.ts +4 -4
- package/dist/dynamic-view.js +7 -7
- package/dist/entity-select.js +4 -4
- package/dist/field-validation-ui.d.ts +2 -2
- package/dist/field-widget-registry.d.ts +1 -1
- package/dist/form-layout-ui.d.ts +1 -1
- package/dist/form-layout.d.ts +1 -1
- package/dist/form-layout.js +1 -1
- package/dist/genui/index.d.ts +1 -1
- package/dist/genui/index.js +1 -1
- package/dist/genui/settings-block.d.ts +1 -1
- package/dist/genui/settings-block.js +3 -3
- package/dist/host-api-client.d.ts +28 -1
- package/dist/host-api-client.d.ts.map +1 -1
- package/dist/host-api-client.js +27 -14
- package/dist/host-api.d.ts +23 -1
- package/dist/host-api.d.ts.map +1 -1
- package/dist/host-api.js +79 -4
- package/dist/hotswap-reload-policy.d.ts +1 -1
- package/dist/hotswap-reload-policy.js +1 -1
- package/dist/icon-picker-field.d.ts +1 -1
- package/dist/icon-picker-field.js +3 -3
- package/dist/icon-resolvers.d.ts +1 -1
- package/dist/icon-resolvers.js +1 -1
- package/dist/icon-spec.js +1 -1
- package/dist/index.d.ts +165 -165
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -148
- package/dist/license/index.d.ts +6 -6
- package/dist/license/index.js +6 -6
- package/dist/license/license-expiry-banner.d.ts +1 -1
- package/dist/license/license-expiry-banner.js +3 -3
- package/dist/license/license-gate.d.ts +1 -1
- package/dist/license/license-gate.js +5 -5
- package/dist/license/license-status-badge.d.ts +1 -1
- package/dist/license/license-status-badge.js +1 -1
- package/dist/license/use-license-t.d.ts +1 -1
- package/dist/license/use-license-t.js +1 -1
- package/dist/license/view.d.ts +1 -1
- package/dist/license/view.js +1 -1
- package/dist/list-include.d.ts +1 -1
- package/dist/manifest-hotswap-subscriber.d.ts +1 -1
- package/dist/manifest-hotswap-subscriber.js +1 -1
- package/dist/metadata-cache.d.ts +1 -1
- package/dist/metadata-cache.js +1 -1
- package/dist/model-action-toolbar.d.ts +1 -1
- package/dist/model-action-toolbar.js +7 -7
- package/dist/nav-permissions.d.ts +1 -1
- package/dist/nav-permissions.js +1 -1
- package/dist/navigation-builder.d.ts +1 -1
- package/dist/navigation-builder.js +1 -1
- package/dist/option-display.d.ts +1 -1
- package/dist/option-display.js +2 -2
- package/dist/option-filter.d.ts +1 -1
- package/dist/option-when.d.ts +1 -1
- package/dist/org-runtime-provider.d.ts +2 -2
- package/dist/org-runtime-provider.js +2 -2
- package/dist/permissions-context.d.ts +1 -1
- package/dist/permissions-manager.js +4 -4
- package/dist/primitives/aging.js +1 -1
- package/dist/primitives/allocation.js +1 -1
- package/dist/primitives/approvals.d.ts +1 -1
- package/dist/primitives/contributions.js +1 -1
- package/dist/primitives/document-kinds.d.ts +1 -1
- package/dist/primitives/index.d.ts +7 -7
- package/dist/primitives/index.js +7 -7
- package/dist/primitives/panels.d.ts +1 -1
- package/dist/primitives/use-contributions.d.ts +2 -2
- package/dist/primitives/use-contributions.js +2 -2
- package/dist/print-document-button.d.ts +1 -1
- package/dist/print-document-button.js +1 -1
- package/dist/provenance.js +3 -3
- package/dist/query-batch.d.ts +1 -1
- package/dist/query-batch.js +1 -1
- package/dist/record-actions.d.ts +2 -2
- package/dist/record-actions.js +2 -2
- package/dist/record-history.d.ts +2 -2
- package/dist/record-history.js +3 -3
- package/dist/record-picker-dialog.js +3 -3
- package/dist/record-picker-option.d.ts +1 -1
- package/dist/record-picker-option.js +1 -1
- package/dist/record-picker.d.ts +5 -0
- package/dist/record-picker.d.ts.map +1 -1
- package/dist/record-picker.js +16 -6
- package/dist/record-prefill-bar.js +1 -1
- package/dist/relation-gallery.js +1 -1
- package/dist/requires-addon.d.ts +1 -1
- package/dist/rich-cells.js +2 -2
- package/dist/rich-url.js +1 -1
- package/dist/row-actions-menu.js +5 -5
- package/dist/searchable-select-field.d.ts +33 -0
- package/dist/searchable-select-field.d.ts.map +1 -0
- package/dist/searchable-select-field.js +50 -0
- package/dist/searchable-select.d.ts +45 -0
- package/dist/searchable-select.d.ts.map +1 -0
- package/dist/searchable-select.js +72 -0
- package/dist/server-error.js +2 -2
- package/dist/setup/addon-config-surface.d.ts +3 -3
- package/dist/setup/addon-config-surface.js +10 -10
- package/dist/setup/connector-blocks-model.d.ts +1 -1
- package/dist/setup/connector-blocks.d.ts +1 -1
- package/dist/setup/connector-blocks.js +6 -6
- package/dist/setup/flow-model.d.ts +1 -1
- package/dist/setup/health-card.d.ts +1 -1
- package/dist/setup/health-card.js +2 -2
- package/dist/setup/index.d.ts +12 -12
- package/dist/setup/index.js +12 -12
- package/dist/setup/records-table.d.ts +1 -1
- package/dist/setup/records-table.js +2 -2
- package/dist/setup/setup-flow.d.ts +1 -1
- package/dist/setup/setup-flow.js +7 -7
- package/dist/setup/setup-form-step.d.ts +1 -1
- package/dist/setup/setup-form-step.js +4 -4
- package/dist/setup/step-status-badge.d.ts +1 -1
- package/dist/setup/step-status-badge.js +2 -2
- package/dist/setup/tone.d.ts +1 -1
- package/dist/setup/types.d.ts +2 -2
- package/dist/sidebar-layout-manager.d.ts +1 -1
- package/dist/sidebar-layout-manager.js +2 -2
- package/dist/slot.js +1 -1
- package/dist/slots/addon-slot.js +4 -4
- package/dist/slots/index.d.ts +2 -2
- package/dist/slots/index.js +2 -2
- package/dist/stage-automations.d.ts +2 -2
- package/dist/stage-automations.js +1 -1
- package/dist/stage-layout.js +1 -1
- package/dist/stage-overrides.d.ts +1 -1
- package/dist/stage-overrides.js +1 -1
- package/dist/supervised-action.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/tri-state-boolean.d.ts +2 -2
- package/dist/tri-state-boolean.js +1 -1
- package/dist/types.d.ts +13 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/upload-field.d.ts +1 -1
- package/dist/upload-field.js +4 -4
- package/dist/use-addon-installed-probe.js +3 -3
- package/dist/use-addon-settings.d.ts +1 -1
- package/dist/use-addon-settings.js +1 -1
- package/dist/use-dynamic-filters.d.ts +2 -2
- package/dist/use-dynamic-filters.js +6 -6
- package/dist/use-edge-device.d.ts +1 -1
- package/dist/use-edge-device.js +2 -2
- package/dist/use-facet-loaders.d.ts +1 -1
- package/dist/use-facet-loaders.js +1 -1
- package/dist/use-flip-animation.d.ts +1 -1
- package/dist/use-flip-animation.js +1 -1
- package/dist/use-host-api-client.d.ts +2 -2
- package/dist/use-host-api-client.d.ts.map +1 -1
- package/dist/use-host-api-client.js +6 -4
- package/dist/use-option-ids.d.ts +1 -1
- package/dist/use-option-ids.js +2 -2
- package/dist/use-options-resolver.d.ts +2 -2
- package/dist/use-options-resolver.js +4 -4
- package/dist/use-org-document-templates.js +1 -1
- package/dist/use-print-document.js +1 -1
- package/dist/use-record-mutation-tick.js +1 -1
- package/dist/validator.d.ts +2 -2
- package/dist/validator.js +1 -1
- package/dist/view-system/card-spec.d.ts +1 -1
- package/dist/view-system/cards-view.d.ts +1 -1
- package/dist/view-system/cards-view.js +2 -2
- package/dist/view-system/index.d.ts +9 -9
- package/dist/view-system/index.js +9 -9
- package/dist/view-system/model-view.d.ts +3 -3
- package/dist/view-system/model-view.js +7 -7
- package/dist/view-system/saved-views.d.ts +1 -1
- package/dist/view-system/use-view-mode.d.ts +1 -1
- package/dist/view-system/view-state.d.ts +1 -1
- package/dist/view-system/view-switcher.d.ts +1 -1
- package/dist/view-system/view-toolbar.d.ts +1 -1
- package/dist/view-system/view-toolbar.js +2 -2
- package/dist/views/calendar-view.d.ts +1 -1
- package/dist/views/calendar-view.js +2 -2
- package/dist/views/chart-view.d.ts +2 -2
- package/dist/views/chart-view.js +2 -2
- package/dist/views/data-source.d.ts +2 -2
- package/dist/views/index.d.ts +3 -3
- package/dist/views/index.js +2 -2
- package/dist/views/map-view.d.ts +1 -1
- package/dist/views/map-view.js +3 -3
- package/dist/views/panels.d.ts +1 -1
- package/dist/views/panels.js +3 -3
- package/dist/views/registry.d.ts +2 -2
- package/dist/views/registry.js +12 -12
- package/dist/views/split-view.d.ts +1 -1
- package/dist/views/split-view.js +4 -4
- package/dist/views/timeline-view.d.ts +1 -1
- package/dist/views/timeline-view.js +3 -3
- package/dist/views/types.d.ts +2 -2
- package/dist/widgets/charts.d.ts +1 -1
- package/dist/widgets/charts.js +2 -2
- package/dist/widgets/lazy-charts.d.ts +1 -1
- package/dist/widgets/lazy-charts.js +2 -2
- package/dist/widgets/renderers.d.ts +2 -2
- package/dist/widgets/renderers.js +2 -2
- package/dist/widgets/widget-card.d.ts +1 -1
- package/dist/widgets/widget-card.js +2 -2
- package/dist/widgets/widget-renderer.d.ts +1 -1
- package/dist/widgets/widget-renderer.js +4 -4
- package/package.json +9 -9
- package/src/__tests__/host-api-client.test.tsx +28 -0
- package/src/__tests__/host-api.test.ts +91 -0
- package/src/__tests__/searchable-select.test.tsx +247 -0
- package/src/action-modal-dispatcher.tsx +16 -0
- package/src/dialogs/dynamic-record.tsx +26 -0
- package/src/dynamic-form.tsx +17 -0
- package/src/dynamic-line-items.tsx +17 -0
- package/src/dynamic-multi-select-field.tsx +5 -4
- package/src/host-api-client.ts +51 -15
- package/src/host-api.ts +81 -3
- package/src/index.ts +2 -1
- package/src/record-picker.tsx +32 -3
- package/src/searchable-select-field.tsx +134 -0
- package/src/searchable-select.ts +87 -0
- package/src/types.ts +12 -0
- package/src/use-host-api-client.ts +5 -3
package/src/index.ts
CHANGED
|
@@ -304,11 +304,12 @@ export {
|
|
|
304
304
|
type PageChromeState,
|
|
305
305
|
type PageChromeStore,
|
|
306
306
|
} from './addon-page-host'
|
|
307
|
-
export { createHostApi, toHostApiError, type CreateHostApiOptions } from './host-api'
|
|
307
|
+
export { createHostApi, toHostApiError, sanitizeRemoteHeaders, PROTECTED_HOST_HEADERS, normalizeTimeout, DEFAULT_MAX_TIMEOUT_MS, HOST_FRESHNESS_KEY, type CreateHostApiOptions } from './host-api'
|
|
308
308
|
export { HostApiProvider, type HostApiProviderProps } from './host-api-context'
|
|
309
309
|
export {
|
|
310
310
|
createHostApiClient,
|
|
311
311
|
type HostApiClient,
|
|
312
|
+
type HostApiClientOptions,
|
|
312
313
|
type HostRequestConfig,
|
|
313
314
|
type AxiosLikeClient,
|
|
314
315
|
} from './host-api-client'
|
package/src/record-picker.tsx
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
PopoverContent,
|
|
48
48
|
PopoverTrigger,
|
|
49
49
|
} from '@asteby/metacore-ui/primitives'
|
|
50
|
+
import { splitHighlight } from '@asteby/metacore-ui/lib'
|
|
50
51
|
import { JOINED_TRIGGER_CLASS, RecordPickerAction, hasRecordPickerAction } from './record-picker-actions'
|
|
51
52
|
import { useDebouncedValue } from './use-debounced-value'
|
|
52
53
|
|
|
@@ -131,6 +132,25 @@ export function useRecordSearch<T>(
|
|
|
131
132
|
return { results, loading, error, pending: enabled && trimmed.length >= minChars && doneFor !== trimmed }
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/** Label text with the query matches wrapped in <mark> (themed, accent-insensitive). */
|
|
136
|
+
function Highlighted({ text, query }: { text: string; query: string }) {
|
|
137
|
+
const parts = splitHighlight(text, query)
|
|
138
|
+
if (parts.length === 1 && !parts[0]!.match) return <>{text}</>
|
|
139
|
+
return (
|
|
140
|
+
<>
|
|
141
|
+
{parts.map((p, i) =>
|
|
142
|
+
p.match ? (
|
|
143
|
+
<mark key={i} className="rounded-[2px] bg-primary/15 px-0 font-semibold text-foreground" data-slot="record-picker-match">
|
|
144
|
+
{p.text}
|
|
145
|
+
</mark>
|
|
146
|
+
) : (
|
|
147
|
+
<span key={i}>{p.text}</span>
|
|
148
|
+
),
|
|
149
|
+
)}
|
|
150
|
+
</>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
134
154
|
const NO_SEARCH = () => Promise.resolve([] as never[])
|
|
135
155
|
|
|
136
156
|
/**
|
|
@@ -215,6 +235,11 @@ export interface RecordPickerProps<T> {
|
|
|
215
235
|
isItemDisabled?: (item: T) => boolean
|
|
216
236
|
/** Check mark column. Default: true in button mode. */
|
|
217
237
|
showCheck?: boolean
|
|
238
|
+
/**
|
|
239
|
+
* Highlight the typed text inside the default option label / description
|
|
240
|
+
* (case and accent insensitive). Ignored when `renderItem` is set. Default false.
|
|
241
|
+
*/
|
|
242
|
+
highlightQuery?: boolean
|
|
218
243
|
|
|
219
244
|
// --- copy -------------------------------------------------------------
|
|
220
245
|
placeholder?: string
|
|
@@ -326,6 +351,7 @@ export function RecordPicker<T>(props: RecordPickerProps<T>) {
|
|
|
326
351
|
loadingText = 'Buscando…',
|
|
327
352
|
errorText = 'No se pudo buscar. Inténtalo de nuevo.',
|
|
328
353
|
minCharsText,
|
|
354
|
+
highlightQuery = false,
|
|
329
355
|
clearLabel = 'Quitar selección',
|
|
330
356
|
listLabel,
|
|
331
357
|
entityLabel = '',
|
|
@@ -552,7 +578,8 @@ export function RecordPicker<T>(props: RecordPickerProps<T>) {
|
|
|
552
578
|
|
|
553
579
|
const optionClass = (on: boolean, dis: boolean) =>
|
|
554
580
|
cx(
|
|
555
|
-
|
|
581
|
+
// Coarse pointers (touch) get a 44px row; mouse keeps the compact one.
|
|
582
|
+
'relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden [@media(pointer:coarse)]:min-h-11',
|
|
556
583
|
on && 'bg-accent text-accent-foreground',
|
|
557
584
|
dis && 'pointer-events-none opacity-50',
|
|
558
585
|
)
|
|
@@ -607,9 +634,11 @@ export function RecordPicker<T>(props: RecordPickerProps<T>) {
|
|
|
607
634
|
) : null}
|
|
608
635
|
{renderLead?.(item, 'option')}
|
|
609
636
|
<span className="flex min-w-0 flex-1 flex-col">
|
|
610
|
-
<span className="line-clamp-2 break-words">{getLabel(item)}</span>
|
|
637
|
+
<span className="line-clamp-2 break-words">{highlightQuery ? <Highlighted text={getLabel(item)} query={trimmed} /> : getLabel(item)}</span>
|
|
611
638
|
{desc != null && desc !== '' ? (
|
|
612
|
-
<span className="truncate text-xs text-muted-foreground">
|
|
639
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
640
|
+
{highlightQuery && typeof desc === 'string' ? <Highlighted text={desc} query={trimmed} /> : desc}
|
|
641
|
+
</span>
|
|
613
642
|
) : null}
|
|
614
643
|
</span>
|
|
615
644
|
{renderTrailing ? (
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SearchableSelectField - the combobox-with-search that replaces the flat
|
|
2
|
+
// <Select> when a STATIC option list is long (a tax-regime catalog with ~25
|
|
3
|
+
// entries, a country list...), so the user types instead of scrolling.
|
|
4
|
+
//
|
|
5
|
+
// It is a thin configuration of the shared <RecordPicker> (the same control
|
|
6
|
+
// DynamicSelectField and EntitySelect use), so it inherits ARIA combobox +
|
|
7
|
+
// listbox with aria-activedescendant, arrows/Home/End/Enter/Esc/Tab, type-ahead
|
|
8
|
+
// on the closed trigger, scroll-to-selected on open, a portaled collision-aware
|
|
9
|
+
// popover and light/dark theming. What it adds:
|
|
10
|
+
// - client-side filtering by label, code (value) and `description`, ignoring
|
|
11
|
+
// case and accents (a code, a word or an unaccented word find the same row);
|
|
12
|
+
// - match highlighting, a "no results" state and a windowed list when the
|
|
13
|
+
// catalog is huge;
|
|
14
|
+
// - a clear (x) when the field is not required.
|
|
15
|
+
//
|
|
16
|
+
// Who renders it: DynamicForm / DynamicRecordDialog / ActionModal / line items,
|
|
17
|
+
// via {@link isSearchableSelect}: `field.searchable === true`, or - unless
|
|
18
|
+
// `searchable === false` - more than SEARCHABLE_SELECT_THRESHOLD options.
|
|
19
|
+
import { useMemo, useState } from 'react'
|
|
20
|
+
import { RecordPicker } from './record-picker'
|
|
21
|
+
import { OptionLead } from './record-picker-option'
|
|
22
|
+
import type { ResolvedOption } from './use-options-resolver'
|
|
23
|
+
import { SEARCHABLE_SELECT_MAX_ROWS, filterSearchableOptions, windowOptions } from './searchable-select'
|
|
24
|
+
|
|
25
|
+
export interface SearchableSelectOption {
|
|
26
|
+
value: string | number
|
|
27
|
+
label: string
|
|
28
|
+
description?: string | null
|
|
29
|
+
color?: string
|
|
30
|
+
icon?: string
|
|
31
|
+
image?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface SearchableSelectFieldProps {
|
|
35
|
+
options: readonly SearchableSelectOption[]
|
|
36
|
+
/** Current value (string | number); empty / nullish = nothing selected. */
|
|
37
|
+
value: unknown
|
|
38
|
+
onChange: (value: string) => void
|
|
39
|
+
id?: string
|
|
40
|
+
/** Accessible name (the field label). */
|
|
41
|
+
ariaLabel?: string
|
|
42
|
+
placeholder?: string
|
|
43
|
+
/** Required fields cannot be cleared. */
|
|
44
|
+
required?: boolean
|
|
45
|
+
disabled?: boolean
|
|
46
|
+
invalid?: boolean
|
|
47
|
+
/** `cell` = compact variant for table / line-item cells. */
|
|
48
|
+
variant?: 'field' | 'cell'
|
|
49
|
+
/** Overrides the "Buscar..." search placeholder. */
|
|
50
|
+
searchPlaceholder?: string
|
|
51
|
+
/** Overrides the "Sin resultados" copy. */
|
|
52
|
+
emptyText?: string
|
|
53
|
+
maxRows?: number
|
|
54
|
+
triggerClassName?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const toResolved = (o: SearchableSelectOption): ResolvedOption => ({
|
|
58
|
+
id: String(o.value),
|
|
59
|
+
value: String(o.value),
|
|
60
|
+
label: o.label,
|
|
61
|
+
name: o.label,
|
|
62
|
+
description: o.description ?? undefined,
|
|
63
|
+
color: o.color,
|
|
64
|
+
icon: o.icon,
|
|
65
|
+
image: o.image,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
export function SearchableSelectField({
|
|
69
|
+
options,
|
|
70
|
+
value,
|
|
71
|
+
onChange,
|
|
72
|
+
id,
|
|
73
|
+
ariaLabel,
|
|
74
|
+
placeholder = 'Seleccionar...',
|
|
75
|
+
required = false,
|
|
76
|
+
disabled = false,
|
|
77
|
+
invalid = false,
|
|
78
|
+
variant = 'field',
|
|
79
|
+
searchPlaceholder = 'Buscar…',
|
|
80
|
+
emptyText = 'Sin resultados',
|
|
81
|
+
maxRows = SEARCHABLE_SELECT_MAX_ROWS,
|
|
82
|
+
triggerClassName,
|
|
83
|
+
}: SearchableSelectFieldProps) {
|
|
84
|
+
const [query, setQuery] = useState('')
|
|
85
|
+
const all = useMemo(() => options.map(toResolved), [options])
|
|
86
|
+
const valueKey = value != null && value !== '' ? String(value) : ''
|
|
87
|
+
const selected = valueKey ? (all.find((o) => String(o.id) === valueKey) ?? null) : null
|
|
88
|
+
|
|
89
|
+
const { rows, hidden } = useMemo(() => {
|
|
90
|
+
const matched = filterSearchableOptions(all, query)
|
|
91
|
+
return windowOptions(matched, maxRows, (o) => String(o.id) === valueKey)
|
|
92
|
+
}, [all, query, maxRows, valueKey])
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<RecordPicker<ResolvedOption>
|
|
96
|
+
slot="searchable-select"
|
|
97
|
+
id={id}
|
|
98
|
+
ariaLabel={ariaLabel}
|
|
99
|
+
items={rows}
|
|
100
|
+
getKey={(o) => String(o.id)}
|
|
101
|
+
getLabel={(o) => o.label}
|
|
102
|
+
getDescription={(o) => o.description}
|
|
103
|
+
// Plain text options get no lead (OptionLead would add an initials avatar).
|
|
104
|
+
renderLead={(o, where) => (o.image || o.icon || o.color ? <OptionLead option={o} size={where === 'option' ? 24 : 20} /> : null)}
|
|
105
|
+
value={valueKey || null}
|
|
106
|
+
selected={selected}
|
|
107
|
+
onSelect={(o) => onChange(String(o.id))}
|
|
108
|
+
onClear={!required && valueKey ? () => onChange('') : undefined}
|
|
109
|
+
query={query}
|
|
110
|
+
onQueryChange={setQuery}
|
|
111
|
+
onOpenChange={(o) => {
|
|
112
|
+
if (!o) setQuery('')
|
|
113
|
+
}}
|
|
114
|
+
placeholder={placeholder}
|
|
115
|
+
searchPlaceholder={searchPlaceholder}
|
|
116
|
+
emptyText={emptyText}
|
|
117
|
+
highlightQuery
|
|
118
|
+
disabled={disabled}
|
|
119
|
+
invalid={invalid}
|
|
120
|
+
variant={variant}
|
|
121
|
+
triggerClassName={triggerClassName}
|
|
122
|
+
listLabel={ariaLabel}
|
|
123
|
+
beforeList={
|
|
124
|
+
hidden > 0 ? (
|
|
125
|
+
<p className="px-3 py-1.5 text-xs text-muted-foreground" data-slot="searchable-select-more" role="status">
|
|
126
|
+
{`Mostrando ${rows.length} de ${rows.length + hidden} — escribe para filtrar`}
|
|
127
|
+
</p>
|
|
128
|
+
) : null
|
|
129
|
+
}
|
|
130
|
+
/>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export default SearchableSelectField
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Pure rules of the searchable select (combobox with a search box) used by the
|
|
2
|
+
// STATIC `select` / `multiselect` widgets. Kept free of React so the threshold
|
|
3
|
+
// and the matching are unit-testable and shared with the table filters.
|
|
4
|
+
import { matchesSearch, normalizeSearchText } from '@asteby/metacore-ui/lib'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Option count above which a static select becomes a searchable combobox when
|
|
8
|
+
* the field does not say otherwise. Mirrors the kernel constant
|
|
9
|
+
* `modelbase.SearchableSelectThreshold`. At or below it the flat select stays.
|
|
10
|
+
*/
|
|
11
|
+
export const SEARCHABLE_SELECT_THRESHOLD = 8
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Rows rendered at once in the list. Static lists are filtered client-side, so
|
|
15
|
+
* a long catalog (hundreds of rows) is windowed instead of painting every row:
|
|
16
|
+
* the match set is cut to this many (the selected option is always kept) and
|
|
17
|
+
* the list says how many more there are. Typing narrows it.
|
|
18
|
+
*/
|
|
19
|
+
export const SEARCHABLE_SELECT_MAX_ROWS = 100
|
|
20
|
+
|
|
21
|
+
export interface SearchableSelectConfig {
|
|
22
|
+
/** `true` forces the combobox, `false` the flat select, unset = by option count. */
|
|
23
|
+
searchable?: boolean | null
|
|
24
|
+
/** Per-field override of the threshold (`searchThreshold`). */
|
|
25
|
+
searchThreshold?: number | null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Should a static select with `count` options render as a searchable combobox? */
|
|
29
|
+
export function isSearchableSelect(field: SearchableSelectConfig | undefined | null, count: number): boolean {
|
|
30
|
+
if (field?.searchable === true) return true
|
|
31
|
+
if (field?.searchable === false) return false
|
|
32
|
+
const t = field?.searchThreshold
|
|
33
|
+
const threshold = typeof t === 'number' && Number.isFinite(t) && t >= 0 ? t : SEARCHABLE_SELECT_THRESHOLD
|
|
34
|
+
return count > threshold
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SearchableOptionLike {
|
|
38
|
+
value: unknown
|
|
39
|
+
label: string
|
|
40
|
+
description?: string | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Text an option is matched against: label, code (value) and description. */
|
|
44
|
+
export function optionHaystack(o: SearchableOptionLike): string {
|
|
45
|
+
return `${o.label ?? ''} ${o.value ?? ''} ${o.description ?? ''}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Filters options by `query` (case/accent insensitive, every token must hit the
|
|
50
|
+
* label, value or description) and ranks them: label or code starts with the
|
|
51
|
+
* query, then a word of the label starts with it, then any other hit. The
|
|
52
|
+
* original order is kept inside each rank. An empty query returns a copy of the
|
|
53
|
+
* list untouched.
|
|
54
|
+
*/
|
|
55
|
+
export function filterSearchableOptions<T extends SearchableOptionLike>(options: readonly T[], query: string): T[] {
|
|
56
|
+
const q = normalizeSearchText(query)
|
|
57
|
+
if (!q) return options.slice()
|
|
58
|
+
const first = q.split(' ')[0]!
|
|
59
|
+
const ranked: Array<{ o: T; rank: number; i: number }> = []
|
|
60
|
+
options.forEach((o, i) => {
|
|
61
|
+
if (!matchesSearch(optionHaystack(o), q)) return
|
|
62
|
+
const label = normalizeSearchText(o.label)
|
|
63
|
+
const code = normalizeSearchText(o.value)
|
|
64
|
+
let rank = 3
|
|
65
|
+
if (label.startsWith(q) || code.startsWith(q)) rank = 0
|
|
66
|
+
else if (label.split(/[^a-z0-9]+/).some((w) => w.startsWith(first))) rank = 1
|
|
67
|
+
else if (label.includes(q)) rank = 2
|
|
68
|
+
ranked.push({ o, rank, i })
|
|
69
|
+
})
|
|
70
|
+
ranked.sort((a, b) => a.rank - b.rank || a.i - b.i)
|
|
71
|
+
return ranked.map((r) => r.o)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Cuts a match list to `max` rows, always keeping the selected one(s) so the
|
|
76
|
+
* list never loses them. Returns the window and how many rows were hidden.
|
|
77
|
+
*/
|
|
78
|
+
export function windowOptions<T>(
|
|
79
|
+
rows: readonly T[],
|
|
80
|
+
max: number,
|
|
81
|
+
isSelected: (o: T) => boolean,
|
|
82
|
+
): { rows: T[]; hidden: number } {
|
|
83
|
+
if (rows.length <= max) return { rows: rows.slice(), hidden: 0 }
|
|
84
|
+
const head = rows.slice(0, max)
|
|
85
|
+
const missing = rows.slice(max).filter(isSelected)
|
|
86
|
+
return { rows: [...head, ...missing], hidden: rows.length - max - missing.length }
|
|
87
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -723,6 +723,8 @@ export interface OptionDef {
|
|
|
723
723
|
icon?: string
|
|
724
724
|
color?: string
|
|
725
725
|
image?: string
|
|
726
|
+
/** Secondary text; matched by the searchable select search box and shown under the label. */
|
|
727
|
+
description?: string
|
|
726
728
|
when?: OptionWhen
|
|
727
729
|
}
|
|
728
730
|
|
|
@@ -752,6 +754,16 @@ export interface ActionFieldDef {
|
|
|
752
754
|
*/
|
|
753
755
|
nullable?: boolean
|
|
754
756
|
options?: OptionDef[]
|
|
757
|
+
/**
|
|
758
|
+
* Searchable select: `true` always renders the combobox with a search box
|
|
759
|
+
* (filters while typing, accent/case-insensitive, by label, code and option
|
|
760
|
+
* `description`), `false` always the flat select, unset = combobox when the
|
|
761
|
+
* field has more than 8 options (`SEARCHABLE_SELECT_THRESHOLD`). The kernel
|
|
762
|
+
* serves it as `searchable` (FieldDef.Searchable). Static selects only.
|
|
763
|
+
*/
|
|
764
|
+
searchable?: boolean
|
|
765
|
+
/** Per-field override of the option count above which the select becomes searchable. */
|
|
766
|
+
searchThreshold?: number
|
|
755
767
|
defaultValue?: any
|
|
756
768
|
placeholder?: string
|
|
757
769
|
searchEndpoint?: string
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { useMemo } from 'react'
|
|
2
2
|
import { useHostApi } from './addon-page-host'
|
|
3
|
-
import { createHostApiClient, type HostApiClient } from './host-api-client'
|
|
3
|
+
import { createHostApiClient, type HostApiClient, type HostApiClientOptions } from './host-api-client'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The addon's HTTP client, built over the host-injected HostApi. Works inside
|
|
7
7
|
* <AddonPageHost> (pages) and <HostApiProvider> (modals, pickers). Without a
|
|
8
8
|
* host it throws a clear error: there is no localStorage / fetch fallback.
|
|
9
9
|
*/
|
|
10
|
-
export function useHostApiClient(): HostApiClient {
|
|
10
|
+
export function useHostApiClient(options?: HostApiClientOptions): HostApiClient {
|
|
11
11
|
const api = useHostApi()
|
|
12
|
-
|
|
12
|
+
const key = JSON.stringify([options?.defaultHeaders ?? null, options?.defaultTimeout ?? null])
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
return useMemo(() => createHostApiClient(api, options), [api, key])
|
|
13
15
|
}
|