@coffer-org/web-ui 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/Markdown.d.ts +4 -0
- package/dist/Markdown.js +13 -0
- package/dist/MarkdownEditor.d.ts +6 -0
- package/dist/MarkdownEditor.js +83 -0
- package/dist/actions/ActionButton.d.ts +7 -0
- package/dist/actions/ActionButton.js +54 -0
- package/dist/actions/PopupBody.d.ts +4 -0
- package/dist/actions/PopupBody.js +8 -0
- package/dist/actions/TemplateHost.d.ts +4 -0
- package/dist/actions/TemplateHost.js +36 -0
- package/dist/actions/registry.d.ts +20 -0
- package/dist/actions/registry.js +9 -0
- package/dist/components/ExtendReasonInfo.d.ts +6 -0
- package/dist/components/ExtendReasonInfo.js +12 -0
- package/dist/components/FavoriteButton.d.ts +8 -0
- package/dist/components/FavoriteButton.js +7 -0
- package/dist/components/Icon.d.ts +6 -0
- package/dist/components/Icon.js +12 -0
- package/dist/components/PageBody.d.ts +4 -0
- package/dist/components/PageBody.js +4 -0
- package/dist/components/RecordInline.d.ts +8 -0
- package/dist/components/RecordInline.js +29 -0
- package/dist/components/SaveStatus.d.ts +1 -0
- package/dist/components/SaveStatus.js +11 -0
- package/dist/components/Toolbar.d.ts +5 -0
- package/dist/components/Toolbar.js +4 -0
- package/dist/components/icons/color.d.ts +2 -0
- package/dist/components/icons/color.js +10 -0
- package/dist/components/icons/flag.d.ts +2 -0
- package/dist/components/icons/flag.js +6 -0
- package/dist/components/icons/lucide.d.ts +2 -0
- package/dist/components/icons/lucide.js +111 -0
- package/dist/components/icons/registry.d.ts +4 -0
- package/dist/components/icons/registry.js +22 -0
- package/dist/components/icons/simple.d.ts +2 -0
- package/dist/components/icons/simple.js +15 -0
- package/dist/components/icons/tabler.d.ts +2 -0
- package/dist/components/icons/tabler.js +11 -0
- package/dist/components/ui/FieldLabel.d.ts +9 -0
- package/dist/components/ui/FieldLabel.js +4 -0
- package/dist/components/ui/badge.d.ts +9 -0
- package/dist/components/ui/badge.js +19 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/button.js +33 -0
- package/dist/components/ui/calendar.d.ts +8 -0
- package/dist/components/ui/calendar.js +72 -0
- package/dist/components/ui/card.d.ts +8 -0
- package/dist/components/ui/card.js +16 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/checkbox.js +8 -0
- package/dist/components/ui/chip-cls.d.ts +1 -0
- package/dist/components/ui/chip-cls.js +1 -0
- package/dist/components/ui/combobox.d.ts +24 -0
- package/dist/components/ui/combobox.js +58 -0
- package/dist/components/ui/confirm.d.ts +10 -0
- package/dist/components/ui/confirm.js +37 -0
- package/dist/components/ui/date-picker.d.ts +5 -0
- package/dist/components/ui/date-picker.js +16 -0
- package/dist/components/ui/dialog.d.ts +16 -0
- package/dist/components/ui/dialog.js +27 -0
- package/dist/components/ui/dropdown-menu.d.ts +15 -0
- package/dist/components/ui/dropdown-menu.js +18 -0
- package/dist/components/ui/input-group.d.ts +16 -0
- package/dist/components/ui/input-group.js +56 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +6 -0
- package/dist/components/ui/label.d.ts +4 -0
- package/dist/components/ui/label.js +7 -0
- package/dist/components/ui/mask-input.d.ts +61 -0
- package/dist/components/ui/mask-input.js +1052 -0
- package/dist/components/ui/month-year-picker.d.ts +10 -0
- package/dist/components/ui/month-year-picker.js +46 -0
- package/dist/components/ui/option-icon.d.ts +15 -0
- package/dist/components/ui/option-icon.js +19 -0
- package/dist/components/ui/phone-input.d.ts +13 -0
- package/dist/components/ui/phone-input.js +53 -0
- package/dist/components/ui/popover.d.ts +11 -0
- package/dist/components/ui/popover.js +28 -0
- package/dist/components/ui/rating.d.ts +44 -0
- package/dist/components/ui/rating.js +501 -0
- package/dist/components/ui/scroll-area.d.ts +5 -0
- package/dist/components/ui/scroll-area.js +11 -0
- package/dist/components/ui/select-combobox.d.ts +25 -0
- package/dist/components/ui/select-combobox.js +36 -0
- package/dist/components/ui/select.d.ts +13 -0
- package/dist/components/ui/select.js +24 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.js +7 -0
- package/dist/components/ui/switch.d.ts +4 -0
- package/dist/components/ui/switch.js +7 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.js +6 -0
- package/dist/components/ui/time-picker.d.ts +84 -0
- package/dist/components/ui/time-picker.js +1258 -0
- package/dist/components/visually-hidden-input.d.ts +10 -0
- package/dist/components/visually-hidden-input.js +96 -0
- package/dist/hooks/use-as-ref.d.ts +3 -0
- package/dist/hooks/use-as-ref.js +10 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +3 -0
- package/dist/hooks/use-lazy-ref.d.ts +3 -0
- package/dist/hooks/use-lazy-ref.js +9 -0
- package/dist/hooks/use-media-query.d.ts +3 -0
- package/dist/hooks/use-media-query.js +26 -0
- package/dist/host-services.d.ts +47 -0
- package/dist/host-services.js +35 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +69 -0
- package/dist/layout.d.ts +29 -0
- package/dist/layout.js +323 -0
- package/dist/lib/cat-color.d.ts +1 -0
- package/dist/lib/cat-color.js +7 -0
- package/dist/lib/compose-refs.d.ts +5 -0
- package/dist/lib/compose-refs.js +38 -0
- package/dist/lib/date-format.d.ts +9 -0
- package/dist/lib/date-format.js +31 -0
- package/dist/lib/format.d.ts +14 -0
- package/dist/lib/format.js +34 -0
- package/dist/lib/json.d.ts +1 -0
- package/dist/lib/json.js +12 -0
- package/dist/lib/multi-value.d.ts +3 -0
- package/dist/lib/multi-value.js +22 -0
- package/dist/lib/record-option.d.ts +7 -0
- package/dist/lib/record-option.js +52 -0
- package/dist/lib/use-record-labels.d.ts +14 -0
- package/dist/lib/use-record-labels.js +130 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/dist/list-view.d.ts +26 -0
- package/dist/list-view.js +11 -0
- package/dist/markdown/blocks.d.ts +10 -0
- package/dist/markdown/blocks.js +57 -0
- package/dist/markdown/extensions.d.ts +6 -0
- package/dist/markdown/extensions.js +25 -0
- package/dist/markdown/slash.d.ts +23 -0
- package/dist/markdown/slash.js +27 -0
- package/dist/markdown/toolbar.d.ts +13 -0
- package/dist/markdown/toolbar.js +119 -0
- package/dist/plugin-ui.d.ts +43 -0
- package/dist/plugin-ui.js +37 -0
- package/dist/registry.d.ts +26 -0
- package/dist/registry.js +169 -0
- package/dist/render/blocks/accordion.d.ts +1 -0
- package/dist/render/blocks/accordion.js +15 -0
- package/dist/render/blocks/aside.d.ts +1 -0
- package/dist/render/blocks/aside.js +14 -0
- package/dist/render/blocks/balance.d.ts +1 -0
- package/dist/render/blocks/balance.js +14 -0
- package/dist/render/blocks/bento.d.ts +1 -0
- package/dist/render/blocks/bento.js +24 -0
- package/dist/render/blocks/block-shell.d.ts +15 -0
- package/dist/render/blocks/block-shell.js +20 -0
- package/dist/render/blocks/calendar.d.ts +1 -0
- package/dist/render/blocks/calendar.js +142 -0
- package/dist/render/blocks/callout.d.ts +1 -0
- package/dist/render/blocks/callout.js +21 -0
- package/dist/render/blocks/chart.d.ts +1 -0
- package/dist/render/blocks/chart.js +46 -0
- package/dist/render/blocks/compare.d.ts +1 -0
- package/dist/render/blocks/compare.js +16 -0
- package/dist/render/blocks/countdown.d.ts +1 -0
- package/dist/render/blocks/countdown.js +36 -0
- package/dist/render/blocks/deck.d.ts +1 -0
- package/dist/render/blocks/deck.js +29 -0
- package/dist/render/blocks/epigraph.d.ts +1 -0
- package/dist/render/blocks/epigraph.js +13 -0
- package/dist/render/blocks/facets.d.ts +1 -0
- package/dist/render/blocks/facets.js +23 -0
- package/dist/render/blocks/figure.d.ts +1 -0
- package/dist/render/blocks/figure.js +13 -0
- package/dist/render/blocks/grid.d.ts +1 -0
- package/dist/render/blocks/grid.js +21 -0
- package/dist/render/blocks/heatmap.d.ts +1 -0
- package/dist/render/blocks/heatmap.js +135 -0
- package/dist/render/blocks/idcard.d.ts +1 -0
- package/dist/render/blocks/idcard.js +30 -0
- package/dist/render/blocks/identity.d.ts +1 -0
- package/dist/render/blocks/identity.js +46 -0
- package/dist/render/blocks/index.d.ts +40 -0
- package/dist/render/blocks/index.js +40 -0
- package/dist/render/blocks/journal.d.ts +1 -0
- package/dist/render/blocks/journal.js +50 -0
- package/dist/render/blocks/ledger.d.ts +1 -0
- package/dist/render/blocks/ledger.js +23 -0
- package/dist/render/blocks/manifest.d.ts +1 -0
- package/dist/render/blocks/manifest.js +50 -0
- package/dist/render/blocks/masthead.d.ts +1 -0
- package/dist/render/blocks/masthead.js +15 -0
- package/dist/render/blocks/meter.d.ts +1 -0
- package/dist/render/blocks/meter.js +32 -0
- package/dist/render/blocks/nutrition.d.ts +1 -0
- package/dist/render/blocks/nutrition.js +27 -0
- package/dist/render/blocks/people.d.ts +1 -0
- package/dist/render/blocks/people.js +35 -0
- package/dist/render/blocks/plaque.d.ts +1 -0
- package/dist/render/blocks/plaque.js +15 -0
- package/dist/render/blocks/properties.d.ts +1 -0
- package/dist/render/blocks/properties.js +22 -0
- package/dist/render/blocks/prose.d.ts +1 -0
- package/dist/render/blocks/prose.js +17 -0
- package/dist/render/blocks/receipt.d.ts +1 -0
- package/dist/render/blocks/receipt.js +23 -0
- package/dist/render/blocks/registry.d.ts +16 -0
- package/dist/render/blocks/registry.js +7 -0
- package/dist/render/blocks/relation-source.d.ts +2 -0
- package/dist/render/blocks/relation-source.js +6 -0
- package/dist/render/blocks/route.d.ts +1 -0
- package/dist/render/blocks/route.js +23 -0
- package/dist/render/blocks/score.d.ts +1 -0
- package/dist/render/blocks/score.js +15 -0
- package/dist/render/blocks/series.d.ts +23 -0
- package/dist/render/blocks/series.js +57 -0
- package/dist/render/blocks/specimen.d.ts +1 -0
- package/dist/render/blocks/specimen.js +19 -0
- package/dist/render/blocks/split.d.ts +1 -0
- package/dist/render/blocks/split.js +15 -0
- package/dist/render/blocks/spread.d.ts +1 -0
- package/dist/render/blocks/spread.js +15 -0
- package/dist/render/blocks/stack.d.ts +1 -0
- package/dist/render/blocks/stack.js +15 -0
- package/dist/render/blocks/stats.d.ts +1 -0
- package/dist/render/blocks/stats.js +23 -0
- package/dist/render/blocks/status.d.ts +1 -0
- package/dist/render/blocks/status.js +18 -0
- package/dist/render/blocks/table.d.ts +11 -0
- package/dist/render/blocks/table.js +136 -0
- package/dist/render/blocks/tabs.d.ts +1 -0
- package/dist/render/blocks/tabs.js +17 -0
- package/dist/render/blocks/terminal.d.ts +1 -0
- package/dist/render/blocks/terminal.js +18 -0
- package/dist/render/blocks/timeline.d.ts +1 -0
- package/dist/render/blocks/timeline.js +31 -0
- package/dist/render/box.d.ts +5 -0
- package/dist/render/box.js +23 -0
- package/dist/render/chrome.d.ts +64 -0
- package/dist/render/chrome.js +92 -0
- package/dist/render/core/amount.d.ts +1 -0
- package/dist/render/core/amount.js +19 -0
- package/dist/render/core/attachment.d.ts +29 -0
- package/dist/render/core/attachment.js +102 -0
- package/dist/render/core/choice.d.ts +1 -0
- package/dist/render/core/choice.js +40 -0
- package/dist/render/core/composite.d.ts +1 -0
- package/dist/render/core/composite.js +132 -0
- package/dist/render/core/datetime.d.ts +2 -0
- package/dist/render/core/datetime.js +215 -0
- package/dist/render/core/dimensions.d.ts +1 -0
- package/dist/render/core/dimensions.js +44 -0
- package/dist/render/core/embed.d.ts +11 -0
- package/dist/render/core/embed.js +99 -0
- package/dist/render/core/file.d.ts +12 -0
- package/dist/render/core/file.js +238 -0
- package/dist/render/core/illustrated.d.ts +39 -0
- package/dist/render/core/illustrated.js +113 -0
- package/dist/render/core/index.d.ts +23 -0
- package/dist/render/core/index.js +23 -0
- package/dist/render/core/layout-elements.d.ts +1 -0
- package/dist/render/core/layout-elements.js +78 -0
- package/dist/render/core/localpath.d.ts +6 -0
- package/dist/render/core/localpath.js +73 -0
- package/dist/render/core/money.d.ts +1 -0
- package/dist/render/core/money.js +39 -0
- package/dist/render/core/number.d.ts +17 -0
- package/dist/render/core/number.js +104 -0
- package/dist/render/core/period.d.ts +1 -0
- package/dist/render/core/period.js +60 -0
- package/dist/render/core/range.d.ts +1 -0
- package/dist/render/core/range.js +55 -0
- package/dist/render/core/reminder.d.ts +2 -0
- package/dist/render/core/reminder.js +56 -0
- package/dist/render/core/source.d.ts +3 -0
- package/dist/render/core/source.js +65 -0
- package/dist/render/core/stepper.d.ts +1 -0
- package/dist/render/core/stepper.js +81 -0
- package/dist/render/core/storage-group.d.ts +1 -0
- package/dist/render/core/storage-group.js +30 -0
- package/dist/render/core/text.d.ts +15 -0
- package/dist/render/core/text.js +370 -0
- package/dist/render/core/tristate.d.ts +1 -0
- package/dist/render/core/tristate.js +42 -0
- package/dist/render/core/weight.d.ts +4 -0
- package/dist/render/core/weight.js +38 -0
- package/dist/render/dispatch.d.ts +12 -0
- package/dist/render/dispatch.js +53 -0
- package/dist/render/display-override.d.ts +25 -0
- package/dist/render/display-override.js +23 -0
- package/dist/render/editor-mode.d.ts +4 -0
- package/dist/render/editor-mode.js +11 -0
- package/dist/render/field-address.d.ts +14 -0
- package/dist/render/field-address.js +10 -0
- package/dist/render/field-errors.d.ts +8 -0
- package/dist/render/field-errors.js +25 -0
- package/dist/render/field-frame.d.ts +20 -0
- package/dist/render/field-frame.js +78 -0
- package/dist/render/field-scope.d.ts +8 -0
- package/dist/render/field-scope.js +25 -0
- package/dist/render/field-width.d.ts +7 -0
- package/dist/render/field-width.js +12 -0
- package/dist/render/form-types.d.ts +12 -0
- package/dist/render/form-types.js +1 -0
- package/dist/render/hybrid-scope.d.ts +5 -0
- package/dist/render/hybrid-scope.js +9 -0
- package/dist/render/image.d.ts +64 -0
- package/dist/render/image.js +322 -0
- package/dist/render/live-kind.d.ts +7 -0
- package/dist/render/live-kind.js +104 -0
- package/dist/render/markdown-view.d.ts +5 -0
- package/dist/render/markdown-view.js +17 -0
- package/dist/render/multi.d.ts +10 -0
- package/dist/render/multi.js +26 -0
- package/dist/render/multiple-chips.d.ts +24 -0
- package/dist/render/multiple-chips.js +18 -0
- package/dist/render/option-list.d.ts +15 -0
- package/dist/render/option-list.js +47 -0
- package/dist/render/option-value.d.ts +20 -0
- package/dist/render/option-value.js +41 -0
- package/dist/render/picker-scrim.d.ts +7 -0
- package/dist/render/picker-scrim.js +32 -0
- package/dist/render/picker-surface.d.ts +5 -0
- package/dist/render/picker-surface.js +9 -0
- package/dist/render/popover-field.d.ts +16 -0
- package/dist/render/popover-field.js +153 -0
- package/dist/render/record-save-ctx.d.ts +11 -0
- package/dist/render/record-save-ctx.js +41 -0
- package/dist/render/shared.d.ts +92 -0
- package/dist/render/shared.js +182 -0
- package/dist/render/slot.d.ts +45 -0
- package/dist/render/slot.js +194 -0
- package/dist/render/sort-rows.d.ts +3 -0
- package/dist/render/sort-rows.js +38 -0
- package/dist/render/use-collection-rows.d.ts +10 -0
- package/dist/render/use-collection-rows.js +11 -0
- package/dist/render/use-field-edit.d.ts +28 -0
- package/dist/render/use-field-edit.js +50 -0
- package/dist/render/use-file-upload.d.ts +10 -0
- package/dist/render/use-file-upload.js +35 -0
- package/dist/render/use-form-bridge.d.ts +21 -0
- package/dist/render/use-form-bridge.js +53 -0
- package/dist/render/use-hybrid.d.ts +2 -0
- package/dist/render/use-hybrid.js +5 -0
- package/dist/render/widgets/attachment-group.d.ts +1 -0
- package/dist/render/widgets/attachment-group.js +35 -0
- package/dist/render/widgets/checklist-content.d.ts +15 -0
- package/dist/render/widgets/checklist-content.js +12 -0
- package/dist/render/widgets/checklist-group.d.ts +11 -0
- package/dist/render/widgets/checklist-group.js +47 -0
- package/dist/render/widgets/checklist-row.d.ts +14 -0
- package/dist/render/widgets/checklist-row.js +14 -0
- package/dist/render/widgets/display.d.ts +33 -0
- package/dist/render/widgets/display.js +97 -0
- package/dist/render/widgets/edit.d.ts +63 -0
- package/dist/render/widgets/edit.js +283 -0
- package/dist/render/widgets/fixed-collection.d.ts +11 -0
- package/dist/render/widgets/fixed-collection.js +34 -0
- package/dist/render/widgets/flow-row.d.ts +14 -0
- package/dist/render/widgets/flow-row.js +27 -0
- package/dist/render/widgets/group-edit.d.ts +9 -0
- package/dist/render/widgets/group-edit.js +23 -0
- package/dist/render/widgets/group-field.d.ts +9 -0
- package/dist/render/widgets/group-field.js +42 -0
- package/dist/render/widgets/group-widgets.d.ts +2 -0
- package/dist/render/widgets/group-widgets.js +41 -0
- package/dist/render/widgets/group.d.ts +26 -0
- package/dist/render/widgets/group.js +139 -0
- package/dist/render/widgets/illustrated-group.d.ts +1 -0
- package/dist/render/widgets/illustrated-group.js +41 -0
- package/dist/render/widgets/table-group.d.ts +11 -0
- package/dist/render/widgets/table-group.js +58 -0
- package/dist/render/widgets/two-cell-group.d.ts +21 -0
- package/dist/render/widgets/two-cell-group.js +42 -0
- package/dist/render/widgets/url-widget.d.ts +7 -0
- package/dist/render/widgets/url-widget.js +15 -0
- package/dist/render/widgets/weekday-grid.d.ts +13 -0
- package/dist/render/widgets/weekday-grid.js +47 -0
- package/dist/render/write.d.ts +5 -0
- package/dist/render/write.js +14 -0
- package/dist/schema-registry.d.ts +6 -0
- package/dist/schema-registry.js +25 -0
- package/dist/site-links.d.ts +13 -0
- package/dist/site-links.js +18 -0
- package/dist/strip-markdown.d.ts +1 -0
- package/dist/strip-markdown.js +11 -0
- package/dist/theme.css +189 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.js +1 -0
- package/package.json +85 -0
package/dist/layout.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { hasValue, hasChildren, isNamedField, isPseudo, isStorageGroup } from '@coffer-org/sdk/fields';
|
|
5
|
+
import { fieldLayout, elementKind, resolveRenderer, resolveFieldSpan } from "./registry.js";
|
|
6
|
+
import { visibleOptions } from '@coffer-org/sdk/condition';
|
|
7
|
+
import { fieldOptions } from "./lib/format.js";
|
|
8
|
+
import { withScopeValues, ParentValuesProvider } from "./render/field-scope.js";
|
|
9
|
+
import { parseJSON } from "./lib/json.js";
|
|
10
|
+
import { FlowRow, FlowCtx } from "./render/widgets/flow-row.js";
|
|
11
|
+
import { STACK, LAYOUT_STACK, GroupTitle, Rail, groupIcon } from "./render/chrome.js";
|
|
12
|
+
import { focusInPopup } from "./render/field-frame.js";
|
|
13
|
+
import { FieldAddressProvider } from "./render/field-address.js";
|
|
14
|
+
import { SlotProvider } from "./render/slot.js";
|
|
15
|
+
import { withChildWidth } from "./render/field-width.js";
|
|
16
|
+
import Markdown from "./Markdown.js";
|
|
17
|
+
function blockCommit(values, setValue) {
|
|
18
|
+
let last = values;
|
|
19
|
+
return (next) => {
|
|
20
|
+
const merged = next;
|
|
21
|
+
let result = undefined;
|
|
22
|
+
for (const k of Object.keys(merged)) {
|
|
23
|
+
if (merged[k] !== last[k])
|
|
24
|
+
result = setValue(k, merged[k]);
|
|
25
|
+
}
|
|
26
|
+
if (result instanceof Promise) {
|
|
27
|
+
void result.then((err) => {
|
|
28
|
+
if (!err)
|
|
29
|
+
last = merged;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
last = merged;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function InfoBlock({ text }) {
|
|
39
|
+
return _jsx(Markdown, { value: text });
|
|
40
|
+
}
|
|
41
|
+
function renderElementBridge(it, { bridge, t }) {
|
|
42
|
+
if (hasValue(it) && it.key !== undefined) {
|
|
43
|
+
const key = it.key;
|
|
44
|
+
if (bridge.isHidden(key))
|
|
45
|
+
return null;
|
|
46
|
+
const r = resolveRenderer({ kind: elementKind(it) });
|
|
47
|
+
if (!r) {
|
|
48
|
+
console.warn(`[LayoutRenderer] no renderer for kind '${elementKind(it)}'`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const field = withScopeValues(it.type, bridge.values);
|
|
52
|
+
const derive = field.derived;
|
|
53
|
+
const value = bridge.getValue(key);
|
|
54
|
+
const keep = field.hints['multiple'] === true
|
|
55
|
+
? Array.isArray(value)
|
|
56
|
+
? value.map(String)
|
|
57
|
+
: parseJSON(value, []).map(String)
|
|
58
|
+
: typeof value === 'string'
|
|
59
|
+
? value
|
|
60
|
+
: undefined;
|
|
61
|
+
const resolvedOptions = fieldOptions(field);
|
|
62
|
+
const selectOptions = resolvedOptions.length
|
|
63
|
+
? visibleOptions(resolvedOptions, bridge.values ?? {}, keep)
|
|
64
|
+
: undefined;
|
|
65
|
+
const node = (_jsx("div", { onBlur: (e) => {
|
|
66
|
+
if (!focusInPopup(e.relatedTarget))
|
|
67
|
+
bridge.touch(key);
|
|
68
|
+
}, children: _jsx(FieldAddressProvider, { fieldKey: key, children: _jsx(SlotProvider, { field: it, value: value, commit: derive ? undefined : (v) => bridge.setValue(key, v), isHidden: bridge.isHidden, mode: derive ? 'view' : bridge.mode, children: _jsx(r.Page, { el: it, field: field, fieldKey: key, value: value, error: bridge.error(key), mode: derive ? 'view' : bridge.mode, label: field.label ? t(field.label) : undefined, required: bridge.requiredOf(key), recordCtx: bridge.recordCtx, selectOptions: selectOptions }) }) }) }));
|
|
69
|
+
const span = resolveFieldSpan(field);
|
|
70
|
+
return { node, layout: fieldLayout(field), span };
|
|
71
|
+
}
|
|
72
|
+
if (hasValue(it)) {
|
|
73
|
+
const r = resolveRenderer({ kind: elementKind(it) });
|
|
74
|
+
if (!r) {
|
|
75
|
+
console.warn(`[LayoutRenderer] no renderer for static kind '${elementKind(it)}'`);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const field = it.type;
|
|
79
|
+
const staticValue = typeof it.value === 'function' ? undefined : it.value;
|
|
80
|
+
const node = (_jsx(SlotProvider, { field: it, value: staticValue, children: _jsx(r.Page, { el: it, field: field, value: staticValue, mode: "view", label: field.label ? t(field.label) : undefined, recordCtx: bridge.recordCtx }) }));
|
|
81
|
+
const span = resolveFieldSpan(field);
|
|
82
|
+
return { node, layout: fieldLayout(field), span };
|
|
83
|
+
}
|
|
84
|
+
if (it.el === 'divider') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (it.el === 'info') {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (it.el === 'button') {
|
|
91
|
+
const r = resolveRenderer({ kind: 'button' });
|
|
92
|
+
if (!r)
|
|
93
|
+
return null;
|
|
94
|
+
const node = _jsx(r.Page, { el: it, value: undefined, mode: bridge.mode, recordCtx: bridge.recordCtx });
|
|
95
|
+
return { node, layout: 'scalar', span: 3 };
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function collect(items, ctx, bridgeCtx, display = 'wrap') {
|
|
100
|
+
const out = [];
|
|
101
|
+
let buffer = [];
|
|
102
|
+
let staticIdx = 0;
|
|
103
|
+
const flush = () => {
|
|
104
|
+
if (buffer.length) {
|
|
105
|
+
out.push({ kind: 'flow', items: buffer, scroll: display === 'scroll' });
|
|
106
|
+
buffer = [];
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
for (const it of items) {
|
|
110
|
+
if (bridgeCtx) {
|
|
111
|
+
if (isPseudo(it) && it.el === 'divider') {
|
|
112
|
+
flush();
|
|
113
|
+
out.push({ kind: 'divider', label: it.label });
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (isPseudo(it) && it.el === 'info') {
|
|
117
|
+
flush();
|
|
118
|
+
out.push({ kind: 'block', node: _jsx(InfoNode, { textKey: it.text }) });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (!hasChildren(it)) {
|
|
122
|
+
const result = renderElementBridge(it, bridgeCtx);
|
|
123
|
+
if (result == null)
|
|
124
|
+
continue;
|
|
125
|
+
if (result.layout === 'block') {
|
|
126
|
+
flush();
|
|
127
|
+
out.push({ kind: 'block', node: result.node });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const itemKey = hasValue(it) && it.key !== undefined ? it.key : `static-${staticIdx++}`;
|
|
131
|
+
buffer.push({
|
|
132
|
+
key: itemKey,
|
|
133
|
+
span: result.span,
|
|
134
|
+
node: _jsx(Fragment, { children: result.node }, itemKey),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (isNamedField(it)) {
|
|
142
|
+
const node = ctx.renderField(it.key, it.type);
|
|
143
|
+
if (node == null)
|
|
144
|
+
continue;
|
|
145
|
+
if (fieldLayout(it.type) === 'block') {
|
|
146
|
+
flush();
|
|
147
|
+
out.push({ kind: 'block', node });
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const span = resolveFieldSpan(it.type);
|
|
151
|
+
buffer.push({ key: it.key, span, node: _jsx(Fragment, { children: node }, it.key) });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (isPseudo(it) && it.el === 'divider') {
|
|
155
|
+
flush();
|
|
156
|
+
out.push({ kind: 'divider', label: it.label });
|
|
157
|
+
}
|
|
158
|
+
else if (isPseudo(it) && it.el === 'info') {
|
|
159
|
+
flush();
|
|
160
|
+
out.push({ kind: 'block', node: _jsx(InfoNode, { textKey: it.text }) });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
flush();
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
function InfoNode({ textKey }) {
|
|
167
|
+
const { t } = useTranslation();
|
|
168
|
+
return _jsx(InfoBlock, { text: t(textKey) });
|
|
169
|
+
}
|
|
170
|
+
function collapseDividers(nodes) {
|
|
171
|
+
const isPlainDivider = (n) => n.kind === 'divider' && !n.label;
|
|
172
|
+
const out = [];
|
|
173
|
+
for (const n of nodes) {
|
|
174
|
+
if (isPlainDivider(n)) {
|
|
175
|
+
if (!out.length)
|
|
176
|
+
continue;
|
|
177
|
+
if (isPlainDivider(out[out.length - 1]))
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
out.push(n);
|
|
181
|
+
}
|
|
182
|
+
while (out.length && isPlainDivider(out[out.length - 1]))
|
|
183
|
+
out.pop();
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
export function SectionShell({ label, icon, labelAfter, children, rail = true, tone = 'group', }) {
|
|
187
|
+
const body = _jsx("div", { className: `flex flex-col min-w-0 ${STACK}`, children: children });
|
|
188
|
+
return (_jsxs("section", { className: `flex flex-col min-w-0 ${STACK}`, children: [label && _jsx(GroupTitle, { label: label, icon: icon, actions: labelAfter, tone: tone }), rail && label ? _jsx(Rail, { children: body }) : body] }));
|
|
189
|
+
}
|
|
190
|
+
function GroupSection({ group, children }) {
|
|
191
|
+
const { t } = useTranslation();
|
|
192
|
+
return (_jsx(SectionShell, { label: group.label ? t(group.label) : undefined, icon: groupIcon(group), children: children }));
|
|
193
|
+
}
|
|
194
|
+
function RowSection({ group, children }) {
|
|
195
|
+
const { t } = useTranslation();
|
|
196
|
+
return (_jsxs("div", { className: "flex flex-col gap-1 min-w-0", children: [group.label && _jsx("span", { className: "text-xs text-muted", children: t(group.label) }), children] }));
|
|
197
|
+
}
|
|
198
|
+
function SheetSection({ group, renderCell, }) {
|
|
199
|
+
const { t } = useTranslation();
|
|
200
|
+
const rows = group.fields.map((el) => (hasChildren(el) ? el.fields : [el]));
|
|
201
|
+
const N = Math.max(1, ...rows.map((r) => r.length));
|
|
202
|
+
let visible = false;
|
|
203
|
+
const slots = [];
|
|
204
|
+
rows.forEach((row, ri) => {
|
|
205
|
+
for (let ci = 0; ci < N; ci++) {
|
|
206
|
+
const cell = row[ci];
|
|
207
|
+
const node = cell ? renderCell(cell) : null;
|
|
208
|
+
if (node)
|
|
209
|
+
visible = true;
|
|
210
|
+
slots.push(_jsx("div", { className: "min-w-0", children: node }, `${ri}-${ci}`));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
if (!visible)
|
|
214
|
+
return null;
|
|
215
|
+
return (_jsx(FlowCtx.Provider, { value: true, children: _jsx(SectionShell, { label: group.label ? t(group.label) : undefined, icon: groupIcon(group), children: _jsx("div", { className: "overflow-x-auto", children: _jsx("div", { className: "grid gap-x-4 gap-y-2 items-start", style: { gridTemplateColumns: `repeat(${N}, max-content)` }, children: slots }) }) }) }));
|
|
216
|
+
}
|
|
217
|
+
function renderNodes(nodes, keyPrefix) {
|
|
218
|
+
const visible = nodes.filter((n) => n.kind !== 'divider' || n.label);
|
|
219
|
+
if (!visible.length)
|
|
220
|
+
return null;
|
|
221
|
+
return nodes.map((n, i) => {
|
|
222
|
+
const key = `${keyPrefix}-${i}`;
|
|
223
|
+
switch (n.kind) {
|
|
224
|
+
case 'flow':
|
|
225
|
+
return _jsx(FlowRow, { items: n.items, scroll: n.scroll }, key);
|
|
226
|
+
case 'block':
|
|
227
|
+
return _jsx(Fragment, { children: n.node }, key);
|
|
228
|
+
case 'group':
|
|
229
|
+
return _jsx(Fragment, { children: n.node }, key);
|
|
230
|
+
case 'divider':
|
|
231
|
+
return renderDivider(n.label, key);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
export function LabelledDivider({ label }) {
|
|
236
|
+
const { t } = useTranslation();
|
|
237
|
+
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "shrink-0 text-xs uppercase tracking-wider text-muted", children: t(label) }), _jsx("div", { className: "flex-1 border-t border-border" })] }));
|
|
238
|
+
}
|
|
239
|
+
function renderDivider(label, key) {
|
|
240
|
+
return label ? _jsx(LabelledDivider, { label: label }, key) : _jsx("hr", { className: "border-border" }, key);
|
|
241
|
+
}
|
|
242
|
+
function renderGroupNode(it, ctx, bridgeCtx) {
|
|
243
|
+
if (bridgeCtx) {
|
|
244
|
+
if (isStorageGroup(it)) {
|
|
245
|
+
const key = it.key;
|
|
246
|
+
const gVal = bridgeCtx.bridge.getValue(key);
|
|
247
|
+
if (bridgeCtx.bridge.isHidden(key))
|
|
248
|
+
return null;
|
|
249
|
+
const r = resolveRenderer({ kind: elementKind(it) });
|
|
250
|
+
if (!r) {
|
|
251
|
+
console.warn(`[LayoutRenderer] no renderer for storage group kind '${elementKind(it)}'`);
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return (_jsx(SlotProvider, { field: it, value: gVal, commit: (v) => bridgeCtx.bridge.setValue(key, v), isHidden: bridgeCtx.bridge.isHidden, mode: bridgeCtx.bridge.mode, children: _jsx(r.Page, { el: it, value: gVal, error: bridgeCtx.bridge.error(key), mode: bridgeCtx.bridge.mode, recordCtx: bridgeCtx.bridge.recordCtx }) }));
|
|
255
|
+
}
|
|
256
|
+
if (it.display === 'sheet') {
|
|
257
|
+
return (_jsx(SheetSection, { group: it, renderCell: (cell) => hasChildren(cell) ? null : (renderElementBridge(cell, bridgeCtx)?.node ?? null) }));
|
|
258
|
+
}
|
|
259
|
+
if (it.kind !== undefined) {
|
|
260
|
+
const r = resolveRenderer({ kind: it.kind });
|
|
261
|
+
if (r) {
|
|
262
|
+
return (_jsx(FlowCtx.Provider, { value: true, children: withChildWidth(r.childWidth, _jsx(SlotProvider, { field: it, value: bridgeCtx.bridge.values, commit: blockCommit(bridgeCtx.bridge.values, bridgeCtx.bridge.setValue), isHidden: bridgeCtx.bridge.isHidden, mode: bridgeCtx.bridge.mode, children: _jsx(r.Page, { el: it, value: undefined, mode: bridgeCtx.bridge.mode, recordCtx: bridgeCtx.bridge.recordCtx }) })) }));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const innerNodes = collapseDividers(collect(it.fields, ctx, bridgeCtx, it.display === 'scroll' ? 'scroll' : 'wrap'));
|
|
266
|
+
const inner = renderNodes(innerNodes, 'g');
|
|
267
|
+
if (!inner)
|
|
268
|
+
return null;
|
|
269
|
+
if (it.display === 'scroll') {
|
|
270
|
+
return _jsx(RowSection, { group: it, children: inner });
|
|
271
|
+
}
|
|
272
|
+
const r = resolveRenderer({ kind: 'group' });
|
|
273
|
+
if (r) {
|
|
274
|
+
return (_jsx(SlotProvider, { field: it, value: undefined, children: _jsx(r.Page, { el: it, value: undefined, mode: bridgeCtx.bridge.mode, recordCtx: bridgeCtx.bridge.recordCtx, children: inner }) }));
|
|
275
|
+
}
|
|
276
|
+
return _jsx(GroupSection, { group: it, children: inner });
|
|
277
|
+
}
|
|
278
|
+
if (isStorageGroup(it)) {
|
|
279
|
+
return ctx.renderGroup?.(it.key, it) ?? null;
|
|
280
|
+
}
|
|
281
|
+
if (it.display === 'sheet') {
|
|
282
|
+
return (_jsx(SheetSection, { group: it, renderCell: (cell) => (isNamedField(cell) ? ctx.renderField(cell.key, cell.type) : null) }));
|
|
283
|
+
}
|
|
284
|
+
if (it.kind !== undefined) {
|
|
285
|
+
const r = resolveRenderer({ kind: it.kind });
|
|
286
|
+
if (r) {
|
|
287
|
+
return (_jsx(FlowCtx.Provider, { value: true, children: withChildWidth(r.childWidth, _jsx(SlotProvider, { field: it, value: ctx.values, commit: ctx.setValue ? blockCommit(ctx.values ?? {}, ctx.setValue) : undefined, isHidden: ctx.isHidden, mode: ctx.mode, children: _jsx(r.Page, { el: it, value: undefined, mode: ctx.mode ?? 'view', recordCtx: { library: '', shelf: '', recordId: null } }) })) }));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const inner = renderNodes(collapseDividers(collect(it.fields, ctx, undefined, it.display === 'scroll' ? 'scroll' : 'wrap')), 'g');
|
|
291
|
+
if (!inner)
|
|
292
|
+
return null;
|
|
293
|
+
return it.display === 'scroll' ? (_jsx(RowSection, { group: it, children: inner })) : (_jsx(GroupSection, { group: it, children: inner }));
|
|
294
|
+
}
|
|
295
|
+
export function LayoutRenderer({ items, ctx }) {
|
|
296
|
+
const { t } = useTranslation();
|
|
297
|
+
const bridgeCtx = ctx.bridge ? { bridge: ctx.bridge, t } : undefined;
|
|
298
|
+
const nodes = [];
|
|
299
|
+
let buffer = [];
|
|
300
|
+
const flushRun = () => {
|
|
301
|
+
if (buffer.length) {
|
|
302
|
+
nodes.push(...collect(buffer, ctx, bridgeCtx));
|
|
303
|
+
buffer = [];
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
for (const it of items) {
|
|
307
|
+
if (hasChildren(it)) {
|
|
308
|
+
flushRun();
|
|
309
|
+
const node = renderGroupNode(it, ctx, bridgeCtx);
|
|
310
|
+
if (node)
|
|
311
|
+
nodes.push({ kind: 'group', node });
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
buffer.push(it);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
flushRun();
|
|
318
|
+
const collapsed = collapseDividers(nodes);
|
|
319
|
+
const rendered = renderNodes(collapsed, 'l');
|
|
320
|
+
if (rendered == null)
|
|
321
|
+
return null;
|
|
322
|
+
return (_jsx(ParentValuesProvider, { values: ctx.bridge?.values, children: _jsx("div", { className: `@container flex flex-col min-w-0 ${LAYOUT_STACK}`, children: rendered }) }));
|
|
323
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function catColor(key: string): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type PossibleRef<T> = React.Ref<T> | undefined;
|
|
3
|
+
declare function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
4
|
+
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>;
|
|
5
|
+
export { composeRefs, useComposedRefs };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
function setRef(ref, value) {
|
|
3
|
+
if (typeof ref === 'function') {
|
|
4
|
+
return ref(value);
|
|
5
|
+
}
|
|
6
|
+
if (ref !== null && ref !== undefined) {
|
|
7
|
+
ref.current = value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function composeRefs(...refs) {
|
|
11
|
+
return (node) => {
|
|
12
|
+
let hasCleanup = false;
|
|
13
|
+
const cleanups = refs.map((ref) => {
|
|
14
|
+
const cleanup = setRef(ref, node);
|
|
15
|
+
if (!hasCleanup && typeof cleanup === 'function') {
|
|
16
|
+
hasCleanup = true;
|
|
17
|
+
}
|
|
18
|
+
return cleanup;
|
|
19
|
+
});
|
|
20
|
+
if (hasCleanup) {
|
|
21
|
+
return () => {
|
|
22
|
+
for (let i = 0; i < cleanups.length; i++) {
|
|
23
|
+
const cleanup = cleanups[i];
|
|
24
|
+
if (typeof cleanup === 'function') {
|
|
25
|
+
cleanup();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setRef(refs[i], null);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useComposedRefs(...refs) {
|
|
36
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
37
|
+
}
|
|
38
|
+
export { composeRefs, useComposedRefs };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function isoToDate(iso: string): Date | undefined;
|
|
2
|
+
export declare function dateToIso(d: Date): string;
|
|
3
|
+
export declare function isoToDisplay(iso: string): string;
|
|
4
|
+
export declare function isoDateTimeToDisplay(iso: string): string;
|
|
5
|
+
export declare function splitDateTime(iso: string): {
|
|
6
|
+
date: string;
|
|
7
|
+
time: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function joinDateTime(date: string, time: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { format, parse, isValid } from 'date-fns';
|
|
2
|
+
export function isoToDate(iso) {
|
|
3
|
+
if (!iso)
|
|
4
|
+
return undefined;
|
|
5
|
+
const d = parse(iso.slice(0, 10), 'yyyy-MM-dd', new Date());
|
|
6
|
+
return isValid(d) ? d : undefined;
|
|
7
|
+
}
|
|
8
|
+
export function dateToIso(d) {
|
|
9
|
+
return format(d, 'yyyy-MM-dd');
|
|
10
|
+
}
|
|
11
|
+
export function isoToDisplay(iso) {
|
|
12
|
+
const d = isoToDate(iso);
|
|
13
|
+
return d ? format(d, 'dd.MM.yyyy') : '';
|
|
14
|
+
}
|
|
15
|
+
export function isoDateTimeToDisplay(iso) {
|
|
16
|
+
if (!iso)
|
|
17
|
+
return '';
|
|
18
|
+
const datePart = isoToDisplay(iso.slice(0, 10));
|
|
19
|
+
if (!datePart)
|
|
20
|
+
return '';
|
|
21
|
+
const time = iso.slice(11, 16);
|
|
22
|
+
return time ? `${datePart} ${time}` : datePart;
|
|
23
|
+
}
|
|
24
|
+
export function splitDateTime(iso) {
|
|
25
|
+
return { date: iso.slice(0, 10), time: iso.slice(11, 16) };
|
|
26
|
+
}
|
|
27
|
+
export function joinDateTime(date, time) {
|
|
28
|
+
if (!date)
|
|
29
|
+
return '';
|
|
30
|
+
return time ? `${date}T${time}` : date;
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FieldMeta, OptionItem } from '@coffer-org/sdk/fields';
|
|
2
|
+
type TFn = (key: string, opts?: Record<string, unknown>) => string;
|
|
3
|
+
export declare function formatDuration(secs: number, t: TFn): string;
|
|
4
|
+
export declare function asBool(v: unknown): boolean;
|
|
5
|
+
type OptionsCarrier = Pick<FieldMeta, 'options'> & {
|
|
6
|
+
hints?: FieldMeta['hints'];
|
|
7
|
+
};
|
|
8
|
+
export declare function fieldOptions(field: OptionsCarrier): OptionItem[];
|
|
9
|
+
export declare function optionLabel(t: TFn, field: OptionsCarrier, value: unknown): string;
|
|
10
|
+
export declare function sortedCountryOptions(t: TFn): {
|
|
11
|
+
code: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { COUNTRIES } from '@coffer-org/sdk/countries';
|
|
2
|
+
import { getOptionList } from "../schema-registry.js";
|
|
3
|
+
export function formatDuration(secs, t) {
|
|
4
|
+
const d = Math.floor(secs / 86400);
|
|
5
|
+
const h = Math.floor((secs % 86400) / 3600);
|
|
6
|
+
const m = Math.floor((secs % 3600) / 60);
|
|
7
|
+
const s = secs % 60;
|
|
8
|
+
const parts = [];
|
|
9
|
+
if (d)
|
|
10
|
+
parts.push(`${d} ${t('form.days')}`);
|
|
11
|
+
if (h)
|
|
12
|
+
parts.push(`${h} ${t('form.hours')}`);
|
|
13
|
+
if (m)
|
|
14
|
+
parts.push(`${m} ${t('form.minutes')}`);
|
|
15
|
+
if (s)
|
|
16
|
+
parts.push(`${s} ${t('form.seconds')}`);
|
|
17
|
+
return parts.length ? parts.join(' ') : `0 ${t('form.seconds')}`;
|
|
18
|
+
}
|
|
19
|
+
export function asBool(v) {
|
|
20
|
+
return v === true || v === 1 || v === '1' || v === 'true';
|
|
21
|
+
}
|
|
22
|
+
export function fieldOptions(field) {
|
|
23
|
+
if (field.options?.length)
|
|
24
|
+
return field.options;
|
|
25
|
+
const src = field.hints?.['source'];
|
|
26
|
+
return src ? getOptionList(src) : [];
|
|
27
|
+
}
|
|
28
|
+
export function optionLabel(t, field, value) {
|
|
29
|
+
const key = fieldOptions(field).find((o) => o.value === String(value))?.title;
|
|
30
|
+
return key ? t(key) : String(value ?? '');
|
|
31
|
+
}
|
|
32
|
+
export function sortedCountryOptions(t) {
|
|
33
|
+
return COUNTRIES.map((c) => ({ code: c.code, name: t(`core.countries.${c.code}`) })).sort((a, b) => a.name.localeCompare(b.name));
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseJSON<T>(v: unknown, fallback: T): T;
|
package/dist/lib/json.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function parseTagValues(v) {
|
|
2
|
+
if (v === null || v === undefined || v === '')
|
|
3
|
+
return [];
|
|
4
|
+
if (Array.isArray(v))
|
|
5
|
+
return v.map(String).filter(Boolean);
|
|
6
|
+
if (typeof v === 'string') {
|
|
7
|
+
if (v.startsWith('[')) {
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(v);
|
|
10
|
+
if (Array.isArray(parsed))
|
|
11
|
+
return parsed.map(String).filter(Boolean);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return v ? [v] : [];
|
|
17
|
+
}
|
|
18
|
+
return [String(v)];
|
|
19
|
+
}
|
|
20
|
+
export function isMultiValued(f) {
|
|
21
|
+
return f.kind === 'tags' || f.hints?.['multiple'] === true;
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { inlineText, inlineImageKey, fieldEntries, isImageKind } from '@coffer-org/sdk/shelf';
|
|
2
|
+
import { mediaUrl } from "../host-services.js";
|
|
3
|
+
function firstImageName(value) {
|
|
4
|
+
if (typeof value !== 'string' || !value)
|
|
5
|
+
return undefined;
|
|
6
|
+
try {
|
|
7
|
+
const p = JSON.parse(value);
|
|
8
|
+
const first = Array.isArray(p) ? p[0] : p;
|
|
9
|
+
if (first && typeof first === 'object' && typeof first.name === 'string')
|
|
10
|
+
return first.name;
|
|
11
|
+
if (typeof first === 'string')
|
|
12
|
+
return first;
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function kindOf(m, key) {
|
|
20
|
+
for (const [k, meta] of fieldEntries(m.fields))
|
|
21
|
+
if (k === key)
|
|
22
|
+
return meta.kind;
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function iconFrom(m, key, row) {
|
|
26
|
+
const kind = kindOf(m, key);
|
|
27
|
+
if (kind && isImageKind(kind)) {
|
|
28
|
+
const name = firstImageName(row[key]);
|
|
29
|
+
return name ? { kind: 'image', value: mediaUrl(name) } : undefined;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
export function recordOption(m, row) {
|
|
34
|
+
const sel = m.views?.select;
|
|
35
|
+
if (sel) {
|
|
36
|
+
const titleKeys = Array.isArray(sel.title) ? sel.title : [sel.title];
|
|
37
|
+
return {
|
|
38
|
+
icon: sel.icon ? iconFrom(m, sel.icon, row) : undefined,
|
|
39
|
+
title: titleKeys
|
|
40
|
+
.map((k) => String(row[k] ?? ''))
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join(' '),
|
|
43
|
+
subtitle: sel.subtitle ? String(row[sel.subtitle] ?? '') || undefined : undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const imgKey = inlineImageKey(m);
|
|
47
|
+
const imgName = imgKey ? firstImageName(row[imgKey]) : undefined;
|
|
48
|
+
return {
|
|
49
|
+
icon: imgName ? { kind: 'image', value: mediaUrl(imgName) } : undefined,
|
|
50
|
+
title: inlineText(m, row),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type LoadState = 'loading' | 'idle' | 'error';
|
|
2
|
+
export declare function clearRecordByIdCache(): void;
|
|
3
|
+
export interface RecordLabels {
|
|
4
|
+
rows: {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}[];
|
|
8
|
+
labelMap: Map<string, string>;
|
|
9
|
+
records: Record<string, unknown>[];
|
|
10
|
+
recordMap: Map<string, Record<string, unknown>>;
|
|
11
|
+
loadState: LoadState;
|
|
12
|
+
}
|
|
13
|
+
export declare function useRecordLabels(library: string, shelf: string, displayKey?: string, filter?: Record<string, string>): RecordLabels;
|
|
14
|
+
export declare function useRecordsByIds(library: string, shelf: string, ids: string[]): Map<string, Record<string, unknown>>;
|