@jsudc/react 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/headless.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/lookup/LookupValue.d.ts +3 -1
- package/dist/lookup/LookupValue.js +21 -3
- package/dist/lookup/LookupValue.js.map +1 -1
- package/dist/lookup/label.d.ts +7 -0
- package/dist/lookup/label.js +14 -1
- package/dist/lookup/label.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/table/cells.js +2 -12
- package/dist/table/cells.js.map +1 -1
- package/dist/table/format.d.ts +4 -0
- package/dist/table/format.js +12 -1
- package/dist/table/format.js.map +1 -1
- package/dist/udc/hooks.d.ts +20 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ npm install @jsudc/react @jsudc/core \
|
|
|
41
41
|
# then the peers of the renderers you register (see Renderers), all of them:
|
|
42
42
|
npm install @tanstack/react-table leaflet recharts @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
|
|
43
43
|
# or straight from a GitHub tag:
|
|
44
|
-
npm install github:digital-cube/jsudc-core#v0.
|
|
44
|
+
npm install github:digital-cube/jsudc-core#v0.8.0 github:digital-cube/jsudc-react#v0.8.0
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
## Quick start
|
|
@@ -1465,7 +1465,7 @@ peer while the default kit is the fallback.
|
|
|
1465
1465
|
Everything the components import that a host is likely to have too is a peer,
|
|
1466
1466
|
so there is one copy of it in the bundle:
|
|
1467
1467
|
|
|
1468
|
-
- `@jsudc/core` ^0.
|
|
1468
|
+
- `@jsudc/core` ^0.8.0 — one copy of the protocol, shared with the host's
|
|
1469
1469
|
own `UdcClient`;
|
|
1470
1470
|
- `react`, `react-dom` ^19 — one React, or hooks break;
|
|
1471
1471
|
- `@tanstack/react-query` ^5 — one `QueryClient` context, shared with the
|
|
@@ -1767,6 +1767,20 @@ only stores and filters keys.
|
|
|
1767
1767
|
is a `lookup_array`. In an `editable` cell a plain click on a label stays in
|
|
1768
1768
|
the cell (double-click edits) and Cmd / Ctrl-click opens the target. A filter
|
|
1769
1769
|
pill on a lookup field shows the labels too.
|
|
1770
|
+
- **Coloured chips.** With `lookup.color_field` (`@jsudc/core` 0.8.0) each
|
|
1771
|
+
chip of a `lookup_array` takes the colour of its target row: the value of that
|
|
1772
|
+
field, a named palette value, is the chip's `data-color`. A tone of the
|
|
1773
|
+
palette (`accent`, `success`, `warning`, `danger`, `info`, `muted`,
|
|
1774
|
+
`default`) draws as that tone's badge, in both themes. Any other name is the
|
|
1775
|
+
host's to map, through two variables on the chip (class `udc-lookup-chip`):
|
|
1776
|
+
|
|
1777
|
+
```css
|
|
1778
|
+
.udc-lookup-chip[data-color="red"] { --udc-chip-bg: oklch(0.95 0.04 25); --udc-chip-fg: oklch(0.5 0.19 25); }
|
|
1779
|
+
.dark .udc-lookup-chip[data-color="red"] { --udc-chip-bg: oklch(0.32 0.08 25); --udc-chip-fg: oklch(0.85 0.09 25); }
|
|
1780
|
+
```
|
|
1781
|
+
|
|
1782
|
+
A name the host does not map, and a row with no value there, draw the
|
|
1783
|
+
default chip. A single `lookup` stays a plain link.
|
|
1770
1784
|
- **One call per lookup field**, not per cell: the table (and the kanban
|
|
1771
1785
|
board) resolve the keys of the rows on screen with `useLookupBatch` and hand
|
|
1772
1786
|
them down through `<UdcLookupBatch>`. A `LookupValue` outside a batch
|
package/dist/headless.js
CHANGED
|
@@ -16,7 +16,7 @@ import { DOC_TAB, SOURCE_TAB, pagingStorageKey, resolvePagingMode, resolveSort,
|
|
|
16
16
|
import { boardFilter, boardFromFilter, boardSource, bucketsOf, byOrder, cardsFilter, groupCards, isOverdue, isReadOnly, newBucketRow, orderOf, planDrop, priorityTone, quickAddRow, replanDrop } from "./kanban/model.js";
|
|
17
17
|
import { persistOrder } from "./kanban/persist.js";
|
|
18
18
|
import { BOARD_PARAM, useKanbanBoard } from "./kanban/useKanbanBoard.js";
|
|
19
|
-
import { lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
19
|
+
import { lookupColor, lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
20
20
|
import { LOOKUP_OPTIONS_LIMIT, optionsFilter, useLookupOptions } from "./lookup/options.js";
|
|
21
21
|
import { asLookup, fetchLookupRows, keyString, lookupKeys, lookupQuery, useUdcLookup, useUdcLookups, valueKeys } from "./lookup/useUdcLookup.js";
|
|
22
22
|
import { AIRPLANE_PATH, TRAILS_FOR_ALL_MAX, airplaneHtml, boundsOf, coordsOf, initialView, markerRadius, markerTone, regionAt, regionById, rotationOf, toMarkers, toNumber, trailMarkers, trailOf } from "./map/model.js";
|
|
@@ -25,7 +25,7 @@ import { createRendererRegistry, rendererEntry, rendererTabs, resolveTab } from
|
|
|
25
25
|
import { isFolderRow } from "./renderers/types.js";
|
|
26
26
|
import { ownsKeys, rowActivationEnabled, useRowActivation } from "./rows/useRowActivation.js";
|
|
27
27
|
import { EMPTY_SELECTION, pageSelectionState, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, setPageSelection, toggleSelection, useRowSelection } from "./rows/useRowSelection.js";
|
|
28
|
-
import { badgeTone, displayText, formatBytes, formatDate, formatDateTime, formatNumber, formatNumberColumn, isBlank, renderKind } from "./table/format.js";
|
|
28
|
+
import { BADGE_TONE, badgeTone, displayText, formatBytes, formatDate, formatDateTime, formatNumber, formatNumberColumn, isBlank, isTone, renderKind } from "./table/format.js";
|
|
29
29
|
import { BG_COLOR, TEXT_COLOR, resolveRowColor } from "./table/style.js";
|
|
30
30
|
import { applyTransforms, formatDatePattern, hasTransforms, parseIsoParts, titlecase, truncate } from "./table/transforms.js";
|
|
31
31
|
import { DEFAULT_VIRTUAL_OVERSCAN, DEFAULT_VIRTUAL_THRESHOLD, bodySlices, keepRange, resolveVirtualization, useRowWindow, virtualizationApplies, visibleRange, withOverscan } from "./table/useRowWindow.js";
|
|
@@ -41,4 +41,4 @@ import { udcKeys } from "./udc/keys.js";
|
|
|
41
41
|
import { windowLocationAdapter } from "./url-state/adapter.js";
|
|
42
42
|
import { createMemoryUrlStateAdapter, prefixUrlStateAdapter } from "./url-state/adapters.js";
|
|
43
43
|
import { UdcUrlStateProvider, useUrlSearchParams, useUrlStateAdapter } from "./url-state/UrlState.js";
|
|
44
|
-
export { ACCENT, AIRPLANE_PATH, ALL_ROWS_MAX, BG_COLOR, BOARD_PARAM, BROWSER_TZ, CARD_MIN_WIDTH, CARD_SPARKLINE, CHART_SLOTS, COMMON_ZONES, COUNT_KEY, DATE_PARAM, DAY, DEFAULT_VIRTUAL_OVERSCAN, DEFAULT_VIRTUAL_THRESHOLD, DOC_TAB, EMPTY_SELECTION, FIRST_VISIT, FROM_PARAM, HOUR, LOOKUP_OPTIONS_LIMIT, MATCH_ALL, MINUTE, PARAM, PRESET_PARAM, REPLY_AUTHOR, SOURCE_TAB, TEXT_COLOR, TO_PARAM, TRAILS_FOR_ALL_MAX, TZ_STORAGE_KEY, TimezoneProvider, UdcActionsProvider, UdcCellsProvider, UdcChangeFeed, UdcChangeFeedContext, UdcClientContext, UdcRenderersProvider, UdcUrlStateProvider, WIN_PARAM, X_KEY, addDays, addMonths, airplaneHtml, allZones, andWindow, applyToListRows, applyTransforms, asLookup, avatarTone, axisFrames, axisValues, badgeTone, barSize, base64UrlToUtf8, boardFilter, boardFromFilter, boardSource, bodySlices, boundsOf, browserZone, bucketsOf, buildTree, bulkActionEligible, byOrder, callAction, canCreate, canDrop, cardSize, cardSlots, cardsFilter, cartesianData, cellComponent, chipCondition, chipsFilter, columnSortable, composeFilter, computeWindow, conditionsToTree, coordsOf, createCellRegistry, createMemoryUrlStateAdapter, createRendererRegistry, createUdcQueryClient, cycleSort, dayKey, dayOf, daysBetween, decodeChipParam, decodeFilterParam, decodeModeParam, decodePageParam, decodeSortParam, displayText, dragResult, dropId, dropParent, eligibleRowActions, encodeChipParam, encodeFilterParam, encodeSortParam, eventColor, eventsOnDay, expandStorageKey, fetchAllRows, fetchLookupRows, findMatchRanges, folderCrumbs, formatAxisValue, formatBytes, formatDate, formatDatePattern, formatDateTime, formatDay, formatNumber, formatNumberColumn, formatTime, formatTimeTick, freshnessOf, groupCards, hasTransforms, highlightParts, i18nKey, idOf, initialView, initials, instantAt, isAllDay, isBlank, isEmptyChip, isExpanded, isFolderRow, isLiveField, isOverdue, isReadOnly, isRowMenuKey, isValidZone, isoInZone, joinFolder, keepRange, keyString, layoutLanes, lazyChildrenQuery, lazyRootsQuery, liveDescribe, liveSort, liveView, loadExpand, lookupExtras, lookupKeys, lookupLabel, lookupQuery, markerRadius, markerTone, maxPointsFor, mergeCellRegistries, metricText, minuteOfDay, movePatch, moveToDay, mutateManyTouches, newBucketRow, newEventRow, numberOf, offsetLabel, offsetMinutes, offsetText, optionsFilter, orderOf, ownsKeys, pageOffset, pageSelectionState, pagingStorageKey, parentLookup, parentOf, parseDayKey, parseDropId, parseIsoParts, parseWall, patchRowInList, persistOrder, planBulkAction, planDrop, planDrop$1 as planTreeDrop, pollInterval, prefixUrlStateAdapter, presetDays, priorityTone, pruneTree, quickAddRow, readWindow, regionAt, regionById, renderKind, rendererEntry, rendererTabs, reparentRequest, replanDrop, replyRow, resolvePagingMode, resolveRowColor, resolveSort, resolveTab, resolveVirtualization, rootCondition, rotationOf, rowActionDefs, rowActionsDisplay, rowActivationEnabled, sameDay, saveExpand, searchExpansion, searchFilter, searchPart, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, selectionTarget, seriesColor, setPageSelection, shouldRetry, siblingsQuery, snapMinutes, sortParamFor, sortSiblings, sourceSortable, splitFolder, startOfDay, stepAnchor, timeTicks, titlecase, toEvents, toMarkers, toNumber, toggleSelection, toggled, trailMarkers, trailOf, treeToConditions, truncate, udcKeys, useBulkActionHandlers, useCalendarUrl, useCellRegistry, useChartWindow, useDataViewState, useKanbanBoard, useLookupOptions, useRendererRegistry, useRowActivation, useRowSelection, useRowWindow, useTimezone, useTreeExpand, useUdcAction, useUdcAllRows, useUdcChangeFeed, useUdcChanges, useUdcClient, useUdcCollection, useUdcCollections, useUdcDescribe, useUdcLookup, useUdcLookups, useUdcMutate, useUdcMutateMany, useUdcSchema, useUdcSource, useUrlSearchParams, useUrlStateAdapter, utf8ToBase64Url, valueKeys, verticalSpan, viewDefaultSort, virtualizationApplies, visibleRange, wallOf, weekStart, weekdayOf, windowBetween, windowCondition, windowFilter, windowLabel, windowLocationAdapter, windowRange, withOverscan, writeWindow, zoneCity, zonedFormat, zonedParts, zonedToInstant };
|
|
44
|
+
export { ACCENT, AIRPLANE_PATH, ALL_ROWS_MAX, BADGE_TONE, BG_COLOR, BOARD_PARAM, BROWSER_TZ, CARD_MIN_WIDTH, CARD_SPARKLINE, CHART_SLOTS, COMMON_ZONES, COUNT_KEY, DATE_PARAM, DAY, DEFAULT_VIRTUAL_OVERSCAN, DEFAULT_VIRTUAL_THRESHOLD, DOC_TAB, EMPTY_SELECTION, FIRST_VISIT, FROM_PARAM, HOUR, LOOKUP_OPTIONS_LIMIT, MATCH_ALL, MINUTE, PARAM, PRESET_PARAM, REPLY_AUTHOR, SOURCE_TAB, TEXT_COLOR, TO_PARAM, TRAILS_FOR_ALL_MAX, TZ_STORAGE_KEY, TimezoneProvider, UdcActionsProvider, UdcCellsProvider, UdcChangeFeed, UdcChangeFeedContext, UdcClientContext, UdcRenderersProvider, UdcUrlStateProvider, WIN_PARAM, X_KEY, addDays, addMonths, airplaneHtml, allZones, andWindow, applyToListRows, applyTransforms, asLookup, avatarTone, axisFrames, axisValues, badgeTone, barSize, base64UrlToUtf8, boardFilter, boardFromFilter, boardSource, bodySlices, boundsOf, browserZone, bucketsOf, buildTree, bulkActionEligible, byOrder, callAction, canCreate, canDrop, cardSize, cardSlots, cardsFilter, cartesianData, cellComponent, chipCondition, chipsFilter, columnSortable, composeFilter, computeWindow, conditionsToTree, coordsOf, createCellRegistry, createMemoryUrlStateAdapter, createRendererRegistry, createUdcQueryClient, cycleSort, dayKey, dayOf, daysBetween, decodeChipParam, decodeFilterParam, decodeModeParam, decodePageParam, decodeSortParam, displayText, dragResult, dropId, dropParent, eligibleRowActions, encodeChipParam, encodeFilterParam, encodeSortParam, eventColor, eventsOnDay, expandStorageKey, fetchAllRows, fetchLookupRows, findMatchRanges, folderCrumbs, formatAxisValue, formatBytes, formatDate, formatDatePattern, formatDateTime, formatDay, formatNumber, formatNumberColumn, formatTime, formatTimeTick, freshnessOf, groupCards, hasTransforms, highlightParts, i18nKey, idOf, initialView, initials, instantAt, isAllDay, isBlank, isEmptyChip, isExpanded, isFolderRow, isLiveField, isOverdue, isReadOnly, isRowMenuKey, isTone, isValidZone, isoInZone, joinFolder, keepRange, keyString, layoutLanes, lazyChildrenQuery, lazyRootsQuery, liveDescribe, liveSort, liveView, loadExpand, lookupColor, lookupExtras, lookupKeys, lookupLabel, lookupQuery, markerRadius, markerTone, maxPointsFor, mergeCellRegistries, metricText, minuteOfDay, movePatch, moveToDay, mutateManyTouches, newBucketRow, newEventRow, numberOf, offsetLabel, offsetMinutes, offsetText, optionsFilter, orderOf, ownsKeys, pageOffset, pageSelectionState, pagingStorageKey, parentLookup, parentOf, parseDayKey, parseDropId, parseIsoParts, parseWall, patchRowInList, persistOrder, planBulkAction, planDrop, planDrop$1 as planTreeDrop, pollInterval, prefixUrlStateAdapter, presetDays, priorityTone, pruneTree, quickAddRow, readWindow, regionAt, regionById, renderKind, rendererEntry, rendererTabs, reparentRequest, replanDrop, replyRow, resolvePagingMode, resolveRowColor, resolveSort, resolveTab, resolveVirtualization, rootCondition, rotationOf, rowActionDefs, rowActionsDisplay, rowActivationEnabled, sameDay, saveExpand, searchExpansion, searchFilter, searchPart, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, selectionTarget, seriesColor, setPageSelection, shouldRetry, siblingsQuery, snapMinutes, sortParamFor, sortSiblings, sourceSortable, splitFolder, startOfDay, stepAnchor, timeTicks, titlecase, toEvents, toMarkers, toNumber, toggleSelection, toggled, trailMarkers, trailOf, treeToConditions, truncate, udcKeys, useBulkActionHandlers, useCalendarUrl, useCellRegistry, useChartWindow, useDataViewState, useKanbanBoard, useLookupOptions, useRendererRegistry, useRowActivation, useRowSelection, useRowWindow, useTimezone, useTreeExpand, useUdcAction, useUdcAllRows, useUdcChangeFeed, useUdcChanges, useUdcClient, useUdcCollection, useUdcCollections, useUdcDescribe, useUdcLookup, useUdcLookups, useUdcMutate, useUdcMutateMany, useUdcSchema, useUdcSource, useUrlSearchParams, useUrlStateAdapter, utf8ToBase64Url, valueKeys, verticalSpan, viewDefaultSort, virtualizationApplies, visibleRange, wallOf, weekStart, weekdayOf, windowBetween, windowCondition, windowFilter, windowLabel, windowLocationAdapter, windowRange, withOverscan, writeWindow, zoneCity, zonedFormat, zonedParts, zonedToInstant };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { type BatchEntry, batchCovers, type LookupBatch, UdcLookupBatch, useLook
|
|
|
16
16
|
export { LookupCombobox } from "./lookup/LookupCombobox.js";
|
|
17
17
|
export { LookupSelectChip } from "./lookup/LookupSelectChip.js";
|
|
18
18
|
export { LookupValue, useLookupLabels, useLookupRows } from "./lookup/LookupValue.js";
|
|
19
|
-
export { lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
19
|
+
export { lookupColor, lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
20
20
|
export { defaultUdcLinks, filterHref, followLink, type UdcLinks, UdcLinksProvider, useUdcLinks, } from "./lookup/links.js";
|
|
21
21
|
export { LOOKUP_OPTIONS_LIMIT, type LookupOption, type LookupOptionsResult, optionsFilter, useLookupOptions, } from "./lookup/options.js";
|
|
22
22
|
export { asLookup, fetchLookupRows, keyString, type LookupRequest, type LookupRows, lookupKeys, lookupQuery, type UdcLookupResult, useUdcLookup, useUdcLookups, valueKeys, } from "./lookup/useUdcLookup.js";
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import { UdcLookupBatch, batchCovers, useLookupBatch, useLookupBatchContext } fr
|
|
|
19
19
|
import { LookupCombobox } from "./lookup/LookupCombobox.js";
|
|
20
20
|
import { LookupSelectChip } from "./lookup/LookupSelectChip.js";
|
|
21
21
|
import { LookupValue, useLookupLabels, useLookupRows } from "./lookup/LookupValue.js";
|
|
22
|
-
import { lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
22
|
+
import { lookupColor, lookupExtras, lookupLabel } from "./lookup/label.js";
|
|
23
23
|
import { UdcLinksProvider, defaultUdcLinks, filterHref, followLink, useUdcLinks } from "./lookup/links.js";
|
|
24
24
|
import { LOOKUP_OPTIONS_LIMIT, optionsFilter, useLookupOptions } from "./lookup/options.js";
|
|
25
25
|
import { asLookup, fetchLookupRows, keyString, lookupKeys, lookupQuery, useUdcLookup, useUdcLookups, valueKeys } from "./lookup/useUdcLookup.js";
|
|
@@ -42,4 +42,4 @@ import { UdcUiProvider, useUiKit } from "./ui-kit/context.js";
|
|
|
42
42
|
import { createMemoryUrlStateAdapter, prefixUrlStateAdapter } from "./url-state/adapters.js";
|
|
43
43
|
import { UdcUrlStateProvider, useUrlSearchParams, useUrlStateAdapter } from "./url-state/UrlState.js";
|
|
44
44
|
import { windowLocationAdapter } from "./url-state/adapter.js";
|
|
45
|
-
export { ALL_ROWS_MAX, BROWSER_TZ, COMMON_ZONES, DEFAULT_VIRTUAL_OVERSCAN, DEFAULT_VIRTUAL_THRESHOLD, EMPTY_SELECTION, EmptyState, ErrorState, FALLBACK_ICON, INTL_LOCALE, LOCALES, LOCALE_STORAGE_KEY, LOOKUP_OPTIONS_LIMIT, LUCIDE_ICONS, LiveIndicator, LookupCombobox, LookupSelectChip, LookupValue, MATCH_ALL, NoRendererState, RowActionsControls, THEME_STORAGE_KEY, TRANSLATIONS, TZ_STORAGE_KEY, ThemeProvider, TimezoneProvider, UDC_SCOPE_CLASS, UdcActionsProvider, UdcCellsProvider, UdcChangeFeed, UdcChangeFeedContext, UdcDataView, UdcI18nProvider, UdcLinksProvider, UdcLookupBatch, UdcProvider, UdcRenderersProvider, UdcUiProvider, UdcUrlStateProvider, allZones, applyToListRows, asLookup, batchCovers, browserZone, bulkActionEligible, callAction, cellComponent, cn, columnSortable, createCellRegistry, createMemoryUrlStateAdapter, createRendererRegistry, createUdcQueryClient, defaultUdcLinks, eligibleRowActions, fetchAllRows, fetchLookupRows, filterHref, followLink, freshnessOf, humanize, i18nKey, intlLocaleOf, isFolderRow, isLocale, isRowMenuKey, isValidZone, keyString, lookup, lookupExtras, lookupKeys, lookupLabel, lookupQuery, makeT, mergeCellRegistries, mergeMessages, messageLocales, mutateManyTouches, offsetLabel, offsetMinutes, optionsFilter, ownsKeys, pageOffset, pageSelectionState, patchRowInList, planBulkAction, pollInterval, prefixUrlStateAdapter, rendererEntry, rendererTabs, resolveChrome, resolveIcon, resolveTab, resolveVirtualization, rowActionDefs, rowActionsColumnWidth, rowActionsDisplay, rowActivationEnabled, rowMenuHandlers, schemaLabelTerms, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, selectionTarget, setPageSelection, shouldRetry, sourceSortable, storage, tableSection, toggleSelection, udcKeys, useBulkActionHandlers, useCellRegistry, useI18n, useLookupBatch, useLookupBatchContext, useLookupLabels, useLookupOptions, useLookupRows, useRendererRegistry, useRowActivation, useRowMenu, useRowSelection, useTheme, useTimezone, useUdcAction, useUdcAllRows, useUdcChangeFeed, useUdcChanges, useUdcClient, useUdcCollection, useUdcCollections, useUdcDescribe, useUdcLinks, useUdcLookup, useUdcLookups, useUdcMutate, useUdcMutateMany, useUdcSchema, useUdcSource, useUiKit, useUrlSearchParams, useUrlStateAdapter, valueKeys, virtualizationApplies, windowLocationAdapter, zoneCity };
|
|
45
|
+
export { ALL_ROWS_MAX, BROWSER_TZ, COMMON_ZONES, DEFAULT_VIRTUAL_OVERSCAN, DEFAULT_VIRTUAL_THRESHOLD, EMPTY_SELECTION, EmptyState, ErrorState, FALLBACK_ICON, INTL_LOCALE, LOCALES, LOCALE_STORAGE_KEY, LOOKUP_OPTIONS_LIMIT, LUCIDE_ICONS, LiveIndicator, LookupCombobox, LookupSelectChip, LookupValue, MATCH_ALL, NoRendererState, RowActionsControls, THEME_STORAGE_KEY, TRANSLATIONS, TZ_STORAGE_KEY, ThemeProvider, TimezoneProvider, UDC_SCOPE_CLASS, UdcActionsProvider, UdcCellsProvider, UdcChangeFeed, UdcChangeFeedContext, UdcDataView, UdcI18nProvider, UdcLinksProvider, UdcLookupBatch, UdcProvider, UdcRenderersProvider, UdcUiProvider, UdcUrlStateProvider, allZones, applyToListRows, asLookup, batchCovers, browserZone, bulkActionEligible, callAction, cellComponent, cn, columnSortable, createCellRegistry, createMemoryUrlStateAdapter, createRendererRegistry, createUdcQueryClient, defaultUdcLinks, eligibleRowActions, fetchAllRows, fetchLookupRows, filterHref, followLink, freshnessOf, humanize, i18nKey, intlLocaleOf, isFolderRow, isLocale, isRowMenuKey, isValidZone, keyString, lookup, lookupColor, lookupExtras, lookupKeys, lookupLabel, lookupQuery, makeT, mergeCellRegistries, mergeMessages, messageLocales, mutateManyTouches, offsetLabel, offsetMinutes, optionsFilter, ownsKeys, pageOffset, pageSelectionState, patchRowInList, planBulkAction, pollInterval, prefixUrlStateAdapter, rendererEntry, rendererTabs, resolveChrome, resolveIcon, resolveTab, resolveVirtualization, rowActionDefs, rowActionsColumnWidth, rowActionsDisplay, rowActivationEnabled, rowMenuHandlers, schemaLabelTerms, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, selectionTarget, setPageSelection, shouldRetry, sourceSortable, storage, tableSection, toggleSelection, udcKeys, useBulkActionHandlers, useCellRegistry, useI18n, useLookupBatch, useLookupBatchContext, useLookupLabels, useLookupOptions, useLookupRows, useRendererRegistry, useRowActivation, useRowMenu, useRowSelection, useTheme, useTimezone, useUdcAction, useUdcAllRows, useUdcChangeFeed, useUdcChanges, useUdcClient, useUdcCollection, useUdcCollections, useUdcDescribe, useUdcLinks, useUdcLookup, useUdcLookups, useUdcMutate, useUdcMutateMany, useUdcSchema, useUdcSource, useUiKit, useUrlSearchParams, useUrlStateAdapter, valueKeys, virtualizationApplies, windowLocationAdapter, zoneCity };
|
|
@@ -15,7 +15,9 @@ export declare function useLookupLabels(def: FieldDef | undefined, value: unknow
|
|
|
15
15
|
* A `lookup` cell: the target's `label_field` as a link to the target
|
|
16
16
|
* collection filtered by the key (`?f=` `{field: <key field>, op: eq}`), the
|
|
17
17
|
* bare key until the label arrives or when the target has no such row. A
|
|
18
|
-
* `lookup_array` is a list of such chips.
|
|
18
|
+
* `lookup_array` is a list of such chips; with `lookup.color_field` each chip
|
|
19
|
+
* takes its row's colour (`data-color`; a tone such as `danger` draws as that
|
|
20
|
+
* badge, any other name through the host's `--udc-chip-bg` / `--udc-chip-fg`).
|
|
19
21
|
*/
|
|
20
22
|
export declare function LookupValue({ def, value, field, editable, }: {
|
|
21
23
|
def: FieldDef;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
|
+
import { BADGE_TONE, isTone } from "../table/format.js";
|
|
2
3
|
import { batchCovers, useLookupBatchContext } from "./batch.js";
|
|
3
|
-
import { lookupExtras, lookupLabel } from "./label.js";
|
|
4
|
+
import { lookupColor, lookupExtras, lookupLabel } from "./label.js";
|
|
4
5
|
import { filterHref, followLink, useUdcLinks } from "./links.js";
|
|
5
6
|
import { keyString, useUdcLookup, valueKeys } from "./useUdcLookup.js";
|
|
6
7
|
import { ROW_ID, lookupKeyField, lookupOf } from "@jsudc/core";
|
|
@@ -33,9 +34,21 @@ function useLookupLabels(def, value, field) {
|
|
|
33
34
|
if (!lookup) return keys;
|
|
34
35
|
return keys.map((k) => lookupLabel(row(k), lookup) ?? k);
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The fill of a chip whose colour is no tone: the host maps the name to
|
|
39
|
+
* `--udc-chip-bg` / `--udc-chip-fg`, e.g.
|
|
40
|
+
* `.udc-lookup-chip[data-color="red"] { --udc-chip-bg: …; --udc-chip-fg: …; }`
|
|
41
|
+
* (and again under `.dark`); a name it does not map draws as the default chip.
|
|
42
|
+
*/
|
|
43
|
+
var NAMED_CHIP = {
|
|
44
|
+
backgroundColor: "var(--udc-chip-bg, var(--muted))",
|
|
45
|
+
color: "var(--udc-chip-fg, var(--foreground))"
|
|
46
|
+
};
|
|
36
47
|
function LookupLink({ lookup, keyValue, row, chip, editable }) {
|
|
37
48
|
const links = useUdcLinks();
|
|
38
49
|
const label = lookupLabel(row, lookup);
|
|
50
|
+
const color = chip ? lookupColor(row, lookup) : void 0;
|
|
51
|
+
const tone = isTone(color) ? color : void 0;
|
|
39
52
|
const field = lookupKeyField(lookup);
|
|
40
53
|
const href = filterHref(links, lookup.collection, {
|
|
41
54
|
field: field === ROW_ID ? ROW_ID : field,
|
|
@@ -56,8 +69,11 @@ function LookupLink({ lookup, keyValue, row, chip, editable }) {
|
|
|
56
69
|
"data-testid": "lookup-link",
|
|
57
70
|
"data-key": keyValue,
|
|
58
71
|
"data-resolved": label !== void 0 || void 0,
|
|
72
|
+
"data-color": color,
|
|
73
|
+
"data-tone": tone,
|
|
59
74
|
title: lookupExtras(row, lookup) ?? label ?? keyValue,
|
|
60
|
-
className: cn("udc:min-w-0 udc:truncate udc:text-foreground udc:underline-offset-2 udc:hover:text-primary udc:hover:underline udc:focus-visible:underline udc:focus-visible:outline-none", chip && "udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:rounded-full udc:
|
|
75
|
+
className: cn("udc:min-w-0 udc:truncate udc:text-foreground udc:underline-offset-2 udc:hover:text-primary udc:hover:underline udc:focus-visible:underline udc:focus-visible:outline-none", chip && "udc-lookup-chip udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:rounded-full udc:px-2 udc:text-[11px] udc:font-medium udc:hover:no-underline", chip && color === void 0 && "udc:bg-muted udc:hover:bg-primary/12", chip && color !== void 0 && "udc:hover:opacity-80", tone && BADGE_TONE[tone], label === void 0 && "udc:font-mono udc:text-muted-foreground"),
|
|
76
|
+
style: color !== void 0 && !tone ? NAMED_CHIP : void 0,
|
|
61
77
|
children: label ?? keyValue
|
|
62
78
|
});
|
|
63
79
|
}
|
|
@@ -65,7 +81,9 @@ function LookupLink({ lookup, keyValue, row, chip, editable }) {
|
|
|
65
81
|
* A `lookup` cell: the target's `label_field` as a link to the target
|
|
66
82
|
* collection filtered by the key (`?f=` `{field: <key field>, op: eq}`), the
|
|
67
83
|
* bare key until the label arrives or when the target has no such row. A
|
|
68
|
-
* `lookup_array` is a list of such chips.
|
|
84
|
+
* `lookup_array` is a list of such chips; with `lookup.color_field` each chip
|
|
85
|
+
* takes its row's colour (`data-color`; a tone such as `danger` draws as that
|
|
86
|
+
* badge, any other name through the host's `--udc-chip-bg` / `--udc-chip-fg`).
|
|
69
87
|
*/
|
|
70
88
|
function LookupValue({ def, value, field, editable = false }) {
|
|
71
89
|
const { lookup, keys, row } = useLookupRows(def, value, field);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LookupValue.js","names":[],"sources":["../../src/lookup/LookupValue.tsx"],"sourcesContent":["import {\n type FieldDef,\n type LookupDef,\n lookupKeyField,\n lookupOf,\n ROW_ID,\n type Row,\n} from \"@jsudc/core\";\nimport type { MouseEvent } from \"react\";\nimport { cn } from \"../lib/utils.js\";\nimport { batchCovers, useLookupBatchContext } from \"./batch.js\";\nimport { lookupExtras, lookupLabel } from \"./label.js\";\nimport { filterHref, followLink, useUdcLinks } from \"./links.js\";\nimport { keyString, useUdcLookup, valueKeys } from \"./useUdcLookup.js\";\n\n/**\n * The labels of a lookup value, from the batch around (`UdcLookupBatch`) or,\n * outside one, from a `useUdcLookup` of its own. `field` names the batch\n * entry. A key not (yet) resolved maps to `undefined`.\n */\nexport function useLookupRows(\n def: FieldDef | undefined,\n value: unknown,\n field?: string,\n): { lookup: LookupDef | undefined; keys: string[]; row: (key: string) => Row | undefined } {\n const lookup = lookupOf(def);\n const keys = valueKeys([value]);\n const batch = useLookupBatchContext();\n const fromBatch = lookup ? batchCovers(batch, field, lookup, keys) : undefined;\n const own = useUdcLookup(lookup ?? { collection: \"\", label_field: \"\" }, keys, {\n enabled: lookup !== undefined && fromBatch === undefined,\n });\n const res = fromBatch ?? own;\n return { lookup, keys, row: (key) => res.row(key) };\n}\n\n/** The labels of a lookup value as strings, the bare key where no label is known. */\nexport function useLookupLabels(\n def: FieldDef | undefined,\n value: unknown,\n field?: string,\n): string[] {\n const { lookup, keys, row } = useLookupRows(def, value, field);\n if (!lookup) return keys;\n return keys.map((k) => lookupLabel(row(k), lookup) ?? k);\n}\n\nfunction LookupLink({\n lookup,\n keyValue,\n row,\n chip,\n editable,\n}: {\n lookup: LookupDef;\n keyValue: string;\n row: Row | undefined;\n chip: boolean;\n editable: boolean;\n}) {\n const links = useUdcLinks();\n const label = lookupLabel(row, lookup);\n const field = lookupKeyField(lookup);\n const href = filterHref(links, lookup.collection, {\n field: field === ROW_ID ? ROW_ID : field,\n op: \"eq\",\n value: keyValue,\n });\n const onClick = (e: MouseEvent) => {\n // In an editable cell a plain click belongs to the cell (double-click edits);\n // Cmd / Ctrl-click still opens the target.\n if (editable && !(e.metaKey || e.ctrlKey || e.button === 1)) {\n e.preventDefault();\n return;\n }\n // The row under the link may have a row_link of its own: the link wins.\n e.stopPropagation();\n followLink(e, href, links);\n };\n return (\n <a\n href={href}\n onClick={onClick}\n data-testid=\"lookup-link\"\n data-key={keyValue}\n data-resolved={label !== undefined || undefined}\n title={lookupExtras(row, lookup) ?? label ?? keyValue}\n className={cn(\n \"udc:min-w-0 udc:truncate udc:text-foreground udc:underline-offset-2 udc:hover:text-primary udc:hover:underline udc:focus-visible:underline udc:focus-visible:outline-none\",\n chip &&\n \"udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:rounded-full udc:
|
|
1
|
+
{"version":3,"file":"LookupValue.js","names":[],"sources":["../../src/lookup/LookupValue.tsx"],"sourcesContent":["import {\n type FieldDef,\n type LookupDef,\n lookupKeyField,\n lookupOf,\n ROW_ID,\n type Row,\n} from \"@jsudc/core\";\nimport type { CSSProperties, MouseEvent } from \"react\";\nimport { cn } from \"../lib/utils.js\";\nimport { BADGE_TONE, isTone } from \"../table/format.js\";\nimport { batchCovers, useLookupBatchContext } from \"./batch.js\";\nimport { lookupColor, lookupExtras, lookupLabel } from \"./label.js\";\nimport { filterHref, followLink, useUdcLinks } from \"./links.js\";\nimport { keyString, useUdcLookup, valueKeys } from \"./useUdcLookup.js\";\n\n/**\n * The labels of a lookup value, from the batch around (`UdcLookupBatch`) or,\n * outside one, from a `useUdcLookup` of its own. `field` names the batch\n * entry. A key not (yet) resolved maps to `undefined`.\n */\nexport function useLookupRows(\n def: FieldDef | undefined,\n value: unknown,\n field?: string,\n): { lookup: LookupDef | undefined; keys: string[]; row: (key: string) => Row | undefined } {\n const lookup = lookupOf(def);\n const keys = valueKeys([value]);\n const batch = useLookupBatchContext();\n const fromBatch = lookup ? batchCovers(batch, field, lookup, keys) : undefined;\n const own = useUdcLookup(lookup ?? { collection: \"\", label_field: \"\" }, keys, {\n enabled: lookup !== undefined && fromBatch === undefined,\n });\n const res = fromBatch ?? own;\n return { lookup, keys, row: (key) => res.row(key) };\n}\n\n/** The labels of a lookup value as strings, the bare key where no label is known. */\nexport function useLookupLabels(\n def: FieldDef | undefined,\n value: unknown,\n field?: string,\n): string[] {\n const { lookup, keys, row } = useLookupRows(def, value, field);\n if (!lookup) return keys;\n return keys.map((k) => lookupLabel(row(k), lookup) ?? k);\n}\n\n/**\n * The fill of a chip whose colour is no tone: the host maps the name to\n * `--udc-chip-bg` / `--udc-chip-fg`, e.g.\n * `.udc-lookup-chip[data-color=\"red\"] { --udc-chip-bg: …; --udc-chip-fg: …; }`\n * (and again under `.dark`); a name it does not map draws as the default chip.\n */\nconst NAMED_CHIP: CSSProperties = {\n backgroundColor: \"var(--udc-chip-bg, var(--muted))\",\n color: \"var(--udc-chip-fg, var(--foreground))\",\n};\n\nfunction LookupLink({\n lookup,\n keyValue,\n row,\n chip,\n editable,\n}: {\n lookup: LookupDef;\n keyValue: string;\n row: Row | undefined;\n chip: boolean;\n editable: boolean;\n}) {\n const links = useUdcLinks();\n const label = lookupLabel(row, lookup);\n // A chip takes the colour of its row (`lookup.color_field`): a tone draws as\n // that tone's badge, any other name is the host's (`data-color`, NAMED_CHIP).\n const color = chip ? lookupColor(row, lookup) : undefined;\n const tone = isTone(color) ? color : undefined;\n const field = lookupKeyField(lookup);\n const href = filterHref(links, lookup.collection, {\n field: field === ROW_ID ? ROW_ID : field,\n op: \"eq\",\n value: keyValue,\n });\n const onClick = (e: MouseEvent) => {\n // In an editable cell a plain click belongs to the cell (double-click edits);\n // Cmd / Ctrl-click still opens the target.\n if (editable && !(e.metaKey || e.ctrlKey || e.button === 1)) {\n e.preventDefault();\n return;\n }\n // The row under the link may have a row_link of its own: the link wins.\n e.stopPropagation();\n followLink(e, href, links);\n };\n return (\n <a\n href={href}\n onClick={onClick}\n data-testid=\"lookup-link\"\n data-key={keyValue}\n data-resolved={label !== undefined || undefined}\n data-color={color}\n data-tone={tone}\n title={lookupExtras(row, lookup) ?? label ?? keyValue}\n className={cn(\n \"udc:min-w-0 udc:truncate udc:text-foreground udc:underline-offset-2 udc:hover:text-primary udc:hover:underline udc:focus-visible:underline udc:focus-visible:outline-none\",\n chip &&\n \"udc-lookup-chip udc:inline-flex udc:h-5 udc:shrink-0 udc:items-center udc:rounded-full udc:px-2 udc:text-[11px] udc:font-medium udc:hover:no-underline\",\n chip && color === undefined && \"udc:bg-muted udc:hover:bg-primary/12\",\n chip && color !== undefined && \"udc:hover:opacity-80\",\n tone && BADGE_TONE[tone],\n label === undefined && \"udc:font-mono udc:text-muted-foreground\",\n )}\n style={color !== undefined && !tone ? NAMED_CHIP : undefined}\n >\n {label ?? keyValue}\n </a>\n );\n}\n\n/**\n * A `lookup` cell: the target's `label_field` as a link to the target\n * collection filtered by the key (`?f=` `{field: <key field>, op: eq}`), the\n * bare key until the label arrives or when the target has no such row. A\n * `lookup_array` is a list of such chips; with `lookup.color_field` each chip\n * takes its row's colour (`data-color`; a tone such as `danger` draws as that\n * badge, any other name through the host's `--udc-chip-bg` / `--udc-chip-fg`).\n */\nexport function LookupValue({\n def,\n value,\n field,\n editable = false,\n}: {\n def: FieldDef;\n value: unknown;\n /** The field, so the batch around the cell (if any) answers for it. */\n field?: string | undefined;\n /** In an editable cell a plain click does not follow the link (Cmd / Ctrl-click does). */\n editable?: boolean;\n}) {\n const { lookup, keys, row } = useLookupRows(def, value, field);\n if (!lookup) return <span className=\"udc:truncate\">{keys.join(\", \")}</span>;\n if (def.type === \"lookup_array\") {\n return (\n <span\n data-testid=\"lookup-chips\"\n className=\"udc:flex udc:min-w-0 udc:items-center udc:gap-1 udc:overflow-hidden\"\n >\n {keys.map((k) => (\n <LookupLink key={k} lookup={lookup} keyValue={k} row={row(k)} chip editable={editable} />\n ))}\n </span>\n );\n }\n const key = keys[0];\n return key === undefined ? null : (\n <LookupLink\n lookup={lookup}\n keyValue={keyString(key)}\n row={row(key)}\n chip={false}\n editable={editable}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,SAAgB,cACd,KACA,OACA,OAC0F;CAC1F,MAAM,SAAS,SAAS,GAAG;CAC3B,MAAM,OAAO,UAAU,CAAC,KAAK,CAAC;CAC9B,MAAM,QAAQ,sBAAsB;CACpC,MAAM,YAAY,SAAS,YAAY,OAAO,OAAO,QAAQ,IAAI,IAAI,KAAA;CACrE,MAAM,MAAM,aAAa,UAAU;EAAE,YAAY;EAAI,aAAa;CAAG,GAAG,MAAM,EAC5E,SAAS,WAAW,KAAA,KAAa,cAAc,KAAA,EACjD,CAAC;CACD,MAAM,MAAM,aAAa;CACzB,OAAO;EAAE;EAAQ;EAAM,MAAM,QAAQ,IAAI,IAAI,GAAG;CAAE;AACpD;;AAGA,SAAgB,gBACd,KACA,OACA,OACU;CACV,MAAM,EAAE,QAAQ,MAAM,QAAQ,cAAc,KAAK,OAAO,KAAK;CAC7D,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,KAAK,KAAK,MAAM,YAAY,IAAI,CAAC,GAAG,MAAM,KAAK,CAAC;AACzD;;;;;;;AAQA,IAAM,aAA4B;CAChC,iBAAiB;CACjB,OAAO;AACT;AAEA,SAAS,WAAW,EAClB,QACA,UACA,KACA,MACA,YAOC;CACD,MAAM,QAAQ,YAAY;CAC1B,MAAM,QAAQ,YAAY,KAAK,MAAM;CAGrC,MAAM,QAAQ,OAAO,YAAY,KAAK,MAAM,IAAI,KAAA;CAChD,MAAM,OAAO,OAAO,KAAK,IAAI,QAAQ,KAAA;CACrC,MAAM,QAAQ,eAAe,MAAM;CACnC,MAAM,OAAO,WAAW,OAAO,OAAO,YAAY;EAChD,OAAO,UAAU,SAAS,SAAS;EACnC,IAAI;EACJ,OAAO;CACT,CAAC;CACD,MAAM,WAAW,MAAkB;EAGjC,IAAI,YAAY,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,IAAI;GAC3D,EAAE,eAAe;GACjB;EACF;EAEA,EAAE,gBAAgB;EAClB,WAAW,GAAG,MAAM,KAAK;CAC3B;CACA,OACE,oBAAC,KAAD;EACQ;EACG;EACT,eAAY;EACZ,YAAU;EACV,iBAAe,UAAU,KAAA,KAAa,KAAA;EACtC,cAAY;EACZ,aAAW;EACX,OAAO,aAAa,KAAK,MAAM,KAAK,SAAS;EAC7C,WAAW,GACT,6KACA,QACE,0JACF,QAAQ,UAAU,KAAA,KAAa,wCAC/B,QAAQ,UAAU,KAAA,KAAa,wBAC/B,QAAQ,WAAW,OACnB,UAAU,KAAA,KAAa,yCACzB;EACA,OAAO,UAAU,KAAA,KAAa,CAAC,OAAO,aAAa,KAAA;EAElD,UAAA,SAAS;CACT,CAAA;AAEP;;;;;;;;;AAUA,SAAgB,YAAY,EAC1B,KACA,OACA,OACA,WAAW,SAQV;CACD,MAAM,EAAE,QAAQ,MAAM,QAAQ,cAAc,KAAK,OAAO,KAAK;CAC7D,IAAI,CAAC,QAAQ,OAAO,oBAAC,QAAD;EAAM,WAAU;EAAgB,UAAA,KAAK,KAAK,IAAI;CAAQ,CAAA;CAC1E,IAAI,IAAI,SAAS,gBACf,OACE,oBAAC,QAAD;EACE,eAAY;EACZ,WAAU;EAET,UAAA,KAAK,KAAK,MACT,oBAAC,YAAD;GAA4B;GAAQ,UAAU;GAAG,KAAK,IAAI,CAAC;GAAG,MAAA;GAAe;EAAW,GAAvE,CAAuE,CACzF;CACG,CAAA;CAGV,MAAM,MAAM,KAAK;CACjB,OAAO,QAAQ,KAAA,IAAY,OACzB,oBAAC,YAAD;EACU;EACR,UAAU,UAAU,GAAG;EACvB,KAAK,IAAI,GAAG;EACZ,MAAM;EACI;CACX,CAAA;AAEL"}
|
package/dist/lookup/label.d.ts
CHANGED
|
@@ -3,3 +3,10 @@ import type { LookupDef, Row } from "@jsudc/core";
|
|
|
3
3
|
export declare function lookupLabel(row: Row | undefined, lookup: LookupDef): string | undefined;
|
|
4
4
|
/** The extra fields of a target row, `name: value` per line (the link's tooltip). */
|
|
5
5
|
export declare function lookupExtras(row: Row | undefined, lookup: LookupDef): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The colour of a target row's chip: the value of `lookup.color_field` (a
|
|
8
|
+
* named palette value such as `danger` or `red`), or `undefined` when the
|
|
9
|
+
* lookup names no colour field or the row has no value there. Read loosely,
|
|
10
|
+
* so a `@jsudc/core` older than `color_field` passes it through as well.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lookupColor(row: Row | undefined, lookup: LookupDef): string | undefined;
|
package/dist/lookup/label.js
CHANGED
|
@@ -11,6 +11,19 @@ function lookupExtras(row, lookup) {
|
|
|
11
11
|
const lines = lookup.extra_fields.map((f) => [f, row[f]]).filter(([, v]) => v !== null && v !== void 0 && v !== "").map(([f, v]) => `${f}: ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
12
12
|
return lines.length ? lines.join("\n") : void 0;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The colour of a target row's chip: the value of `lookup.color_field` (a
|
|
16
|
+
* named palette value such as `danger` or `red`), or `undefined` when the
|
|
17
|
+
* lookup names no colour field or the row has no value there. Read loosely,
|
|
18
|
+
* so a `@jsudc/core` older than `color_field` passes it through as well.
|
|
19
|
+
*/
|
|
20
|
+
function lookupColor(row, lookup) {
|
|
21
|
+
const field = lookup.color_field;
|
|
22
|
+
if (!row || typeof field !== "string" || field === "") return void 0;
|
|
23
|
+
const v = row[field];
|
|
24
|
+
if (typeof v === "number") return String(v);
|
|
25
|
+
return typeof v === "string" && v.trim() !== "" ? v.trim() : void 0;
|
|
26
|
+
}
|
|
27
|
+
export { lookupColor, lookupExtras, lookupLabel };
|
|
15
28
|
|
|
16
29
|
//# sourceMappingURL=label.js.map
|
package/dist/lookup/label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label.js","names":[],"sources":["../../src/lookup/label.ts"],"sourcesContent":["import type { LookupDef, Row } from \"@jsudc/core\";\n\n/** What a target row is called: its `label_field`, or `undefined` when it has none. */\nexport function lookupLabel(row: Row | undefined, lookup: LookupDef): string | undefined {\n const v = row?.[lookup.label_field];\n if (v === null || v === undefined || v === \"\") return undefined;\n return typeof v === \"string\" ? v : String(v);\n}\n\n/** The extra fields of a target row, `name: value` per line (the link's tooltip). */\nexport function lookupExtras(row: Row | undefined, lookup: LookupDef): string | undefined {\n if (!row || !lookup.extra_fields?.length) return undefined;\n const lines = lookup.extra_fields\n .map((f) => [f, row[f]] as const)\n .filter(([, v]) => v !== null && v !== undefined && v !== \"\")\n .map(([f, v]) => `${f}: ${typeof v === \"string\" ? v : JSON.stringify(v)}`);\n return lines.length ? lines.join(\"\\n\") : undefined;\n}\n"],"mappings":";;AAGA,SAAgB,YAAY,KAAsB,QAAuC;CACvF,MAAM,IAAI,MAAM,OAAO;CACvB,IAAI,MAAM,QAAQ,MAAM,KAAA,KAAa,MAAM,IAAI,OAAO,KAAA;CACtD,OAAO,OAAO,MAAM,WAAW,IAAI,OAAO,CAAC;AAC7C;;AAGA,SAAgB,aAAa,KAAsB,QAAuC;CACxF,IAAI,CAAC,OAAO,CAAC,OAAO,cAAc,QAAQ,OAAO,KAAA;CACjD,MAAM,QAAQ,OAAO,aAClB,KAAK,MAAM,CAAC,GAAG,IAAI,EAAE,CAAU,CAAC,CAChC,QAAQ,GAAG,OAAO,MAAM,QAAQ,MAAM,KAAA,KAAa,MAAM,EAAE,CAAC,CAC5D,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,IAAI,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,CAAC,GAAG;CAC3E,OAAO,MAAM,SAAS,MAAM,KAAK,IAAI,IAAI,KAAA;AAC3C"}
|
|
1
|
+
{"version":3,"file":"label.js","names":[],"sources":["../../src/lookup/label.ts"],"sourcesContent":["import type { LookupDef, Row } from \"@jsudc/core\";\n\n/** What a target row is called: its `label_field`, or `undefined` when it has none. */\nexport function lookupLabel(row: Row | undefined, lookup: LookupDef): string | undefined {\n const v = row?.[lookup.label_field];\n if (v === null || v === undefined || v === \"\") return undefined;\n return typeof v === \"string\" ? v : String(v);\n}\n\n/** The extra fields of a target row, `name: value` per line (the link's tooltip). */\nexport function lookupExtras(row: Row | undefined, lookup: LookupDef): string | undefined {\n if (!row || !lookup.extra_fields?.length) return undefined;\n const lines = lookup.extra_fields\n .map((f) => [f, row[f]] as const)\n .filter(([, v]) => v !== null && v !== undefined && v !== \"\")\n .map(([f, v]) => `${f}: ${typeof v === \"string\" ? v : JSON.stringify(v)}`);\n return lines.length ? lines.join(\"\\n\") : undefined;\n}\n\n/**\n * The colour of a target row's chip: the value of `lookup.color_field` (a\n * named palette value such as `danger` or `red`), or `undefined` when the\n * lookup names no colour field or the row has no value there. Read loosely,\n * so a `@jsudc/core` older than `color_field` passes it through as well.\n */\nexport function lookupColor(row: Row | undefined, lookup: LookupDef): string | undefined {\n const field: unknown = lookup.color_field;\n if (!row || typeof field !== \"string\" || field === \"\") return undefined;\n const v = row[field];\n if (typeof v === \"number\") return String(v);\n return typeof v === \"string\" && v.trim() !== \"\" ? v.trim() : undefined;\n}\n"],"mappings":";;AAGA,SAAgB,YAAY,KAAsB,QAAuC;CACvF,MAAM,IAAI,MAAM,OAAO;CACvB,IAAI,MAAM,QAAQ,MAAM,KAAA,KAAa,MAAM,IAAI,OAAO,KAAA;CACtD,OAAO,OAAO,MAAM,WAAW,IAAI,OAAO,CAAC;AAC7C;;AAGA,SAAgB,aAAa,KAAsB,QAAuC;CACxF,IAAI,CAAC,OAAO,CAAC,OAAO,cAAc,QAAQ,OAAO,KAAA;CACjD,MAAM,QAAQ,OAAO,aAClB,KAAK,MAAM,CAAC,GAAG,IAAI,EAAE,CAAU,CAAC,CAChC,QAAQ,GAAG,OAAO,MAAM,QAAQ,MAAM,KAAA,KAAa,MAAM,EAAE,CAAC,CAC5D,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,IAAI,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,CAAC,GAAG;CAC3E,OAAO,MAAM,SAAS,MAAM,KAAK,IAAI,IAAI,KAAA;AAC3C;;;;;;;AAQA,SAAgB,YAAY,KAAsB,QAAuC;CACvF,MAAM,QAAiB,OAAO;CAC9B,IAAI,CAAC,OAAO,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO,KAAA;CAC9D,MAAM,IAAI,IAAI;CACd,IAAI,OAAO,MAAM,UAAU,OAAO,OAAO,CAAC;CAC1C,OAAO,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,IAAI,KAAA;AAC/D"}
|