@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
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { clientToMeta, partValueKey, partValueKeys } from '@coffer-org/sdk/fields';
|
|
5
|
+
import { resolveUnits } from '@coffer-org/sdk/units';
|
|
6
|
+
import { parseJSON } from "../../lib/json.js";
|
|
7
|
+
import { useRecordLabels, useRecordsByIds } from "../../lib/use-record-labels.js";
|
|
8
|
+
import { recordOption } from "../../lib/record-option.js";
|
|
9
|
+
import { getShelf } from "../../schema-registry.js";
|
|
10
|
+
import { Input } from "../../components/ui/input.js";
|
|
11
|
+
import { InputGroup, InputGroupAddon, InputGroupInput } from "../../components/ui/input-group.js";
|
|
12
|
+
import { Button } from "../../components/ui/button.js";
|
|
13
|
+
import { Combobox, ChipsCombobox } from "../../components/ui/select-combobox.js";
|
|
14
|
+
import { Plus } from 'lucide-react';
|
|
15
|
+
import { RecordInline } from "../../components/RecordInline.js";
|
|
16
|
+
import { RemoveBtn, AddBtn, MultipleChips, CheckLegend, colsToCheckRow, checkRowToCols, Dash, } from "../shared.js";
|
|
17
|
+
import { FieldSlot } from "../dispatch.js";
|
|
18
|
+
import { FieldLabel } from "../chrome.js";
|
|
19
|
+
import { measuredChipContent, measuredUnitLabel } from "./display.js";
|
|
20
|
+
import { ChecklistRow } from "./checklist-row.js";
|
|
21
|
+
import { ChecklistContent, clientChecklistContentFields } from "./checklist-content.js";
|
|
22
|
+
import { FlowRow } from "./flow-row.js";
|
|
23
|
+
export function RowWidget({ value, onChange, field, t, recordCtx = { library: '', shelf: '', recordId: '' }, }) {
|
|
24
|
+
const multiple = field.hints['rowMultiple'] === true;
|
|
25
|
+
const subs = field.hints['fields'] ?? [];
|
|
26
|
+
const unique = field.hints['unique'] ?? [];
|
|
27
|
+
const fixedSubs = new Set((field.parts ?? []).filter((p) => p.mode !== 'stored').map(partValueKey));
|
|
28
|
+
const idRef = useRef(0);
|
|
29
|
+
const keyed = (rs) => rs.map((data) => ({ id: ++idRef.current, data }));
|
|
30
|
+
const blank = () => Object.fromEntries(subs.map((s) => [s.key, '']));
|
|
31
|
+
const parse = () => {
|
|
32
|
+
const v = parseJSON(value, multiple ? [] : {});
|
|
33
|
+
if (multiple)
|
|
34
|
+
return Array.isArray(v) ? v : [];
|
|
35
|
+
return [v && !Array.isArray(v) && Object.keys(v).length ? v : blank()];
|
|
36
|
+
};
|
|
37
|
+
const [rows, setRows] = useState(() => keyed(parse()));
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!value)
|
|
40
|
+
setRows(multiple ? [] : keyed([blank()]));
|
|
41
|
+
}, [value]);
|
|
42
|
+
const rowFilled = (r) => subs.some((s) => {
|
|
43
|
+
const v = (r[s.key] ?? '').trim();
|
|
44
|
+
return s.prim === 'checkbox' ? v === 'true' : v !== '';
|
|
45
|
+
});
|
|
46
|
+
function save(next) {
|
|
47
|
+
setRows(next);
|
|
48
|
+
const filled = next.map((r) => r.data).filter(rowFilled);
|
|
49
|
+
if (multiple)
|
|
50
|
+
onChange(filled.length ? filled : '');
|
|
51
|
+
else
|
|
52
|
+
onChange(filled.length ? filled[0] : '');
|
|
53
|
+
}
|
|
54
|
+
function updateRow(idx, key, v) {
|
|
55
|
+
save(rows.map((r, i) => (i === idx ? { ...r, data: { ...r.data, [key]: String(v) } } : r)));
|
|
56
|
+
}
|
|
57
|
+
function usedElsewhere(key, idx) {
|
|
58
|
+
if (!unique.includes(key))
|
|
59
|
+
return [];
|
|
60
|
+
return rows
|
|
61
|
+
.filter((_, i) => i !== idx)
|
|
62
|
+
.map((r) => r.data[key] ?? '')
|
|
63
|
+
.filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
function renderRow({ id, data: row }, idx) {
|
|
66
|
+
return (_jsxs("div", { className: "flex items-start gap-2 flex-wrap border border-border rounded-xl p-3", children: [subs.map((sub) => fixedSubs.has(sub.key) ? (_jsxs("div", { className: "flex flex-col gap-0.5 flex-1 min-w-32", children: [sub.label ? _jsx(FieldLabel, { label: t(sub.label) }) : null, _jsx("div", { className: "flex h-9 items-center rounded-lg border border-transparent px-3 text-sm text-muted", children: row[sub.key] || _jsx(Dash, {}) })] }, sub.key)) : (_jsx("div", { className: "flex flex-col gap-0.5 flex-1 min-w-32", children: _jsx(FieldSlot, { field: clientToMeta(sub), value: sub.prim === 'checkbox' ? row[sub.key] === 'true' : (row[sub.key] ?? ''), excludeValues: usedElsewhere(sub.key, idx), onChange: (v) => updateRow(idx, sub.key, v), label: sub.label ? t(sub.label) : undefined, mode: "edit", recordCtx: recordCtx }) }, sub.key))), multiple && _jsx(RemoveBtn, { className: "mt-6", onClick: () => save(rows.filter((_, i) => i !== idx)) })] }, id));
|
|
67
|
+
}
|
|
68
|
+
return (_jsxs("div", { className: "flex flex-col gap-2.5", children: [rows.map(renderRow), multiple && _jsx(AddBtn, { onClick: () => setRows((r) => [...r, ...keyed([blank()])]), children: t('form.addRow') })] }));
|
|
69
|
+
}
|
|
70
|
+
export function MeasuredWidget({ value, onChange, field, }) {
|
|
71
|
+
const { t } = useTranslation();
|
|
72
|
+
const units = useMemo(() => resolveUnits(field.hints['units']) ?? [], [field.hints]);
|
|
73
|
+
const unitPart = field.parts?.find((p) => p.role === 'unit');
|
|
74
|
+
const unitFixed = unitPart != null && unitPart.mode !== 'stored';
|
|
75
|
+
const valuePart = field.parts?.find((p) => p.role === 'value');
|
|
76
|
+
const valueFixed = valuePart != null && valuePart.mode !== 'stored';
|
|
77
|
+
const slots = useMemo(() => partValueKeys((field.parts ?? [])), [field.parts]);
|
|
78
|
+
const vKey = slots['value'] ?? 'value';
|
|
79
|
+
const uKey = slots['unit'] ?? 'unit';
|
|
80
|
+
const pinnedUnit = unitFixed && typeof unitPart.value === 'string' ? unitPart.value : '';
|
|
81
|
+
const parsed = useMemo(() => {
|
|
82
|
+
const obj = value && typeof value === 'object'
|
|
83
|
+
? value
|
|
84
|
+
: parseJSON(String(value), null);
|
|
85
|
+
if (obj == null || typeof obj !== 'object')
|
|
86
|
+
return { value: '', unit: pinnedUnit || (units[0]?.value ?? '') };
|
|
87
|
+
return { value: (obj[vKey] ?? ''), unit: (obj[uKey] ?? '') };
|
|
88
|
+
}, [value, units, pinnedUnit, vKey, uKey]);
|
|
89
|
+
const save = (next) => {
|
|
90
|
+
if (valueFixed) {
|
|
91
|
+
onChange({ [uKey]: next.unit });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
onChange(next.value !== ''
|
|
95
|
+
? { [vKey]: next.value, [uKey]: next.unit }
|
|
96
|
+
: '');
|
|
97
|
+
};
|
|
98
|
+
return (_jsxs(InputGroup, { className: "min-w-0", children: [valueFixed ? (_jsx("div", { className: "flex h-9 flex-1 min-w-0 items-center px-3 text-sm text-muted", children: parsed.value === '' ? _jsx(Dash, {}) : String(parsed.value) })) : (_jsx(InputGroupInput, { type: "number", className: "min-w-0", value: parsed.value === '' ? '' : String(parsed.value), min: field.hints['min'], max: field.hints['max'], step: field.hints['step'] ?? 'any', onChange: (e) => {
|
|
99
|
+
const n = parseFloat(e.target.value);
|
|
100
|
+
save({ ...parsed, value: isNaN(n) ? '' : n });
|
|
101
|
+
}, placeholder: "0" })), _jsx(InputGroupAddon, { align: "inline-end", className: "pr-1", children: unitFixed ? (_jsx("span", { className: "px-2 text-xs text-muted", children: measuredUnitLabel(field, parsed.unit || pinnedUnit, t) })) : (_jsx(Combobox, { value: parsed.unit || '', onChange: (u) => save({ ...parsed, unit: u }), items: units.map((u) => ({ value: u.value, title: t(u.label) })), triggerClassName: "h-7 gap-1 border-0 bg-transparent px-2 text-muted shadow-none focus:ring-0" })) })] }));
|
|
102
|
+
}
|
|
103
|
+
export function RelationPickerWidget({ field, value, onChange, excludeValues, }) {
|
|
104
|
+
const { t } = useTranslation();
|
|
105
|
+
const library = field.relation?.library ?? '';
|
|
106
|
+
const shelf = field.relation?.shelf ?? '';
|
|
107
|
+
const multi = Boolean(field.hints['multi']);
|
|
108
|
+
const displayKey = String(field.hints['displayKey'] ?? 'name');
|
|
109
|
+
const filterQuery = useMemo(() => {
|
|
110
|
+
const f = field.relation?.filter;
|
|
111
|
+
if (!f)
|
|
112
|
+
return undefined;
|
|
113
|
+
return Object.fromEntries(Object.entries(f).map(([k, v]) => [k, String(v)]));
|
|
114
|
+
}, [field.relation?.filter]);
|
|
115
|
+
const { labelMap, records, loadState } = useRecordLabels(library, shelf, displayKey, filterQuery);
|
|
116
|
+
const m = getShelf(library, shelf);
|
|
117
|
+
const selected = useMemo(() => {
|
|
118
|
+
if (!value)
|
|
119
|
+
return [];
|
|
120
|
+
if (multi) {
|
|
121
|
+
if (Array.isArray(value))
|
|
122
|
+
return value.map(String);
|
|
123
|
+
return parseJSON(value, []).map(String);
|
|
124
|
+
}
|
|
125
|
+
return [String(value)];
|
|
126
|
+
}, [value, multi]);
|
|
127
|
+
const selectedMap = useRecordsByIds(library, shelf, selected);
|
|
128
|
+
const mergedRecords = useMemo(() => {
|
|
129
|
+
const byId = new Map(records.map((r) => [String(r.id), r]));
|
|
130
|
+
for (const [id, row] of selectedMap)
|
|
131
|
+
if (!byId.has(id))
|
|
132
|
+
byId.set(id, row);
|
|
133
|
+
return [...byId.values()];
|
|
134
|
+
}, [records, selectedMap]);
|
|
135
|
+
const items = useMemo(() => mergedRecords
|
|
136
|
+
.filter((r) => String(r.id) === String(value) || selected.includes(String(r.id)) || !excludeValues?.includes(String(r.id)))
|
|
137
|
+
.map((r) => {
|
|
138
|
+
const opt = m ? recordOption(m, r) : { title: String(r.id) };
|
|
139
|
+
const node = m ? _jsx(RecordInline, { shelf: m, row: r, size: "sm", height: 28 }) : undefined;
|
|
140
|
+
return { value: String(r.id), title: opt.title, icon: opt.icon, subtitle: opt.subtitle, node };
|
|
141
|
+
}), [mergedRecords, excludeValues, value, selected, m]);
|
|
142
|
+
const labelOf = (id) => labelMap.get(id) ?? items.find((it) => it.value === id)?.title ?? id;
|
|
143
|
+
if (loadState === 'loading')
|
|
144
|
+
return _jsx("p", { className: "text-muted text-sm py-1", children: t('form.loading') });
|
|
145
|
+
if (loadState === 'error')
|
|
146
|
+
return _jsx("p", { className: "text-danger text-sm py-1", children: t('form.loadError') });
|
|
147
|
+
if (!items.length)
|
|
148
|
+
return _jsx("p", { className: "text-muted text-sm py-1", children: t('form.noRecords') });
|
|
149
|
+
if (!multi)
|
|
150
|
+
return _jsx(Combobox, { value: value == null ? '' : String(value), onChange: onChange, items: items });
|
|
151
|
+
return (_jsx(ChipsCombobox, { selected: selected, items: items, placeholder: t('form.addRecord'), labelOf: labelOf, onChange: (next) => onChange(next.length ? next : '') }));
|
|
152
|
+
}
|
|
153
|
+
function emptyCheckRow(n) {
|
|
154
|
+
return { text: '', checks: Array(n).fill(false) };
|
|
155
|
+
}
|
|
156
|
+
export function CheckWidget({ value, onChange, field, recordCtx = { library: '', shelf: '', recordId: null }, }) {
|
|
157
|
+
const slots = field.hints['slots'] ?? [''];
|
|
158
|
+
const contentFields = clientChecklistContentFields(field.hints['fields']);
|
|
159
|
+
const [data, setData] = useState(() => parseJSON(value, {}));
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!value)
|
|
162
|
+
setData({});
|
|
163
|
+
}, [value, slots.length]);
|
|
164
|
+
const row = contentFields.length
|
|
165
|
+
? {
|
|
166
|
+
text: String(data.text ?? ''),
|
|
167
|
+
checks: Array.from({ length: slots.length }, (_, i) => data['check' + i] === true),
|
|
168
|
+
}
|
|
169
|
+
: colsToCheckRow(value, slots.length);
|
|
170
|
+
function emit(next) {
|
|
171
|
+
setData(next);
|
|
172
|
+
const hasContent = contentFields.length
|
|
173
|
+
? contentFields.some((f) => {
|
|
174
|
+
const v = next[f.key];
|
|
175
|
+
return v != null && v !== '' && !(Array.isArray(v) && v.length === 0);
|
|
176
|
+
})
|
|
177
|
+
: String(next.text ?? '').trim() !== '';
|
|
178
|
+
const legacyChecks = Array.isArray(next.checks) ? next.checks : [];
|
|
179
|
+
const hasChecks = slots.some((_, i) => next['check' + i] === true) || slots.some((_, i) => legacyChecks[i] === true);
|
|
180
|
+
if (contentFields.length)
|
|
181
|
+
onChange(hasContent || hasChecks ? next : '');
|
|
182
|
+
else {
|
|
183
|
+
const legacyRow = {
|
|
184
|
+
text: String(next.text ?? ''),
|
|
185
|
+
checks: slots.map((_, i) => next['check' + i] === true || legacyChecks[i] === true),
|
|
186
|
+
};
|
|
187
|
+
onChange(hasContent || hasChecks ? checkRowToCols(legacyRow) : '');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx(ChecklistRow, { row: row, slotCount: slots.length, editing: true, onChange: (next) => {
|
|
191
|
+
const updated = { ...data };
|
|
192
|
+
slots.forEach((_, i) => {
|
|
193
|
+
updated['check' + i] = next.checks[i] === true;
|
|
194
|
+
});
|
|
195
|
+
if (!contentFields.length)
|
|
196
|
+
updated.text = next.text;
|
|
197
|
+
emit(updated);
|
|
198
|
+
}, content: contentFields.length ? (_jsx(ChecklistContent, { fields: contentFields, row: data, editing: true, onChange: (key, value) => emit({ ...data, [key]: value }), recordCtx: recordCtx })) : undefined }), _jsx(CheckLegend, { slots: slots })] }));
|
|
199
|
+
}
|
|
200
|
+
export function MultiCheckInput({ value, onChange, field, }) {
|
|
201
|
+
const { t } = useTranslation();
|
|
202
|
+
const slots = field.hints['slots'] ?? [''];
|
|
203
|
+
const [rows, setRows] = useState(() => parseJSON(value, []));
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (!value)
|
|
206
|
+
setRows([]);
|
|
207
|
+
}, [value]);
|
|
208
|
+
function save(next) {
|
|
209
|
+
setRows(next);
|
|
210
|
+
const filled = next.filter((r) => r.text.trim() !== '' || r.checks.some(Boolean));
|
|
211
|
+
onChange(filled.length ? filled : '');
|
|
212
|
+
}
|
|
213
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5 py-1", children: [rows.map((row, idx) => (_jsx(ChecklistRow, { row: row, slotCount: slots.length, editing: true, onChange: (r) => save(rows.map((x, i) => (i === idx ? r : x))), onRemove: () => save(rows.filter((_, i) => i !== idx)) }, idx))), _jsx(CheckLegend, { slots: slots }), _jsx(AddBtn, { onClick: () => setRows((r) => [...r, emptyCheckRow(slots.length)]), children: t('form.addItem') })] }));
|
|
214
|
+
}
|
|
215
|
+
export function KeyValueWidget({ value, onChange, multiple = true, option, keyLabel, valueLabel, recordCtx = { library: '', shelf: '', recordId: '' }, }) {
|
|
216
|
+
const { t } = useTranslation();
|
|
217
|
+
const kLabel = keyLabel ?? t('form.keyPlaceholder');
|
|
218
|
+
const vLabel = valueLabel ?? t('form.valuePlaceholderShort');
|
|
219
|
+
const [rows, setRows] = useState(() => {
|
|
220
|
+
if (Array.isArray(value))
|
|
221
|
+
return value;
|
|
222
|
+
if (!value)
|
|
223
|
+
return [];
|
|
224
|
+
return parseJSON(value, []);
|
|
225
|
+
});
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (!value || (Array.isArray(value) && value.length === 0) || value === '[]')
|
|
228
|
+
setRows([]);
|
|
229
|
+
}, [value]);
|
|
230
|
+
function save(next) {
|
|
231
|
+
setRows(next);
|
|
232
|
+
const valid = next.filter((p) => p.key.trim());
|
|
233
|
+
onChange(valid.length ? valid.map((p) => ({ key: p.key.trim(), value: p.value })) : '');
|
|
234
|
+
}
|
|
235
|
+
function updatePairValue(i, v) {
|
|
236
|
+
save(rows.map((x, idx) => (idx === i ? { ...x, value: v } : x)));
|
|
237
|
+
}
|
|
238
|
+
const canAdd = multiple || rows.length < 1;
|
|
239
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(FlowRow, { items: rows.map((item, idx) => ({
|
|
240
|
+
key: String(idx),
|
|
241
|
+
node: (_jsxs("div", { className: "flex flex-col gap-0.5 w-56 max-w-full min-w-0", children: [_jsxs("div", { className: "flex items-center gap-1 min-w-0", children: [_jsx(Input, { placeholder: kLabel, value: item.key, className: "h-6 px-1 min-w-0 text-[11px] font-semibold uppercase text-muted", autoComplete: "off", onChange: (e) => save(rows.map((x, i) => (i === idx ? { ...x, key: e.target.value } : x))) }), _jsx(RemoveBtn, { onClick: () => save(rows.filter((_, i) => i !== idx)) })] }), _jsx(FieldSlot, { bare: true, field: option, value: item.value, mode: "edit", onChange: (v) => updatePairValue(idx, String(v)), recordCtx: recordCtx })] })),
|
|
242
|
+
})) }), canAdd && (_jsxs(AddBtn, { onClick: () => setRows((r) => [...r, { key: '', value: '' }]), children: [kLabel, "/", vLabel] }))] }));
|
|
243
|
+
}
|
|
244
|
+
function parseMeasuredItems(value) {
|
|
245
|
+
const isItem = (x) => !!x && typeof x === 'object' && 'unit' in x;
|
|
246
|
+
if (Array.isArray(value))
|
|
247
|
+
return value.filter(isItem);
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(String(value ?? ''));
|
|
250
|
+
if (Array.isArray(parsed)) {
|
|
251
|
+
return parsed
|
|
252
|
+
.map((it) => {
|
|
253
|
+
if (isItem(it))
|
|
254
|
+
return it;
|
|
255
|
+
try {
|
|
256
|
+
return JSON.parse(String(it));
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
.filter(Boolean);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
}
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
export function MeasuredMultiInput({ field, value, onChange, }) {
|
|
270
|
+
const { t } = useTranslation();
|
|
271
|
+
const items = useMemo(() => parseMeasuredItems(value), [value]);
|
|
272
|
+
const [draft, setDraft] = useState('');
|
|
273
|
+
function save(next) {
|
|
274
|
+
onChange(next.length ? next : '');
|
|
275
|
+
}
|
|
276
|
+
function add() {
|
|
277
|
+
if (!draft || typeof draft !== 'object' || draft.value === '')
|
|
278
|
+
return;
|
|
279
|
+
save([...items, draft]);
|
|
280
|
+
setDraft('');
|
|
281
|
+
}
|
|
282
|
+
return (_jsx(MultipleChips, { items: items, content: measuredChipContent(field, t), onRemove: (idx) => save(items.filter((_, i) => i !== idx)), editor: _jsxs("div", { className: "flex gap-2 items-center min-w-0", children: [_jsx("div", { className: "flex-1 min-w-0", children: _jsx(MeasuredWidget, { value: draft, onChange: (v) => setDraft(v), field: field }) }), _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: add, children: _jsx(Plus, { size: 14 }) })] }) }));
|
|
283
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContainerNode } from '@coffer-org/sdk/fields';
|
|
2
|
+
import type { RecordCtx, FieldMode } from '../../types.ts';
|
|
3
|
+
type Row = Record<string, unknown>;
|
|
4
|
+
export declare function FixedCollection({ group, value, onChange, recordCtx, mode, }: {
|
|
5
|
+
group: ContainerNode;
|
|
6
|
+
value: unknown;
|
|
7
|
+
onChange: (v: Row[]) => void;
|
|
8
|
+
recordCtx: RecordCtx;
|
|
9
|
+
mode?: FieldMode;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { isNamedField } from '@coffer-org/sdk/fields';
|
|
4
|
+
import { optionLabel as fmtOptionLabel, fieldOptions } from "../../lib/format.js";
|
|
5
|
+
import { FieldSlot } from "../dispatch.js";
|
|
6
|
+
import { FieldLabel, Rail, STACK, GroupTitle, groupIcon, useGroupDepth, groupScopeClass } from "../chrome.js";
|
|
7
|
+
import { FlowRow } from "./flow-row.js";
|
|
8
|
+
import { subFull } from "./group.js";
|
|
9
|
+
import { useGroupEdit } from "./group-edit.js";
|
|
10
|
+
import { useHybridScope } from "../hybrid-scope.js";
|
|
11
|
+
export function FixedCollection({ group, value, onChange, recordCtx, mode = 'edit', }) {
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
const depth = useGroupDepth();
|
|
14
|
+
const g = useGroupEdit(mode, value, (v) => onChange(v));
|
|
15
|
+
const editing = g.mode !== 'view';
|
|
16
|
+
const live = useHybridScope() && mode === 'view';
|
|
17
|
+
const byKey = group.view?.by;
|
|
18
|
+
const by = group.fields.find((f) => isNamedField(f) && f.key === byKey);
|
|
19
|
+
const valueFields = group.fields.filter((f) => isNamedField(f) && f.key !== byKey);
|
|
20
|
+
const byOpts = fieldOptions(by.type);
|
|
21
|
+
const stored = Array.isArray(g.value) ? g.value : [];
|
|
22
|
+
const rows = byOpts.map((opt) => stored.find((r) => String(r[by.key] ?? '') === String(opt.value)) ?? { [by.key]: opt.value });
|
|
23
|
+
function commit(next) {
|
|
24
|
+
g.onChange(next.filter((r) => valueFields.some((f) => r[f.key] != null && r[f.key] !== '')));
|
|
25
|
+
}
|
|
26
|
+
function update(idx, key, v) {
|
|
27
|
+
commit(rows.map((r, i) => (i === idx ? { ...r, [key]: v } : r)));
|
|
28
|
+
}
|
|
29
|
+
return (_jsxs("fieldset", { className: `${groupScopeClass(depth)} flex flex-col min-w-0 ${STACK}`, children: [_jsx(GroupTitle, { as: "legend", label: t(group.label), icon: groupIcon(group), actions: live ? null : g.actions }), _jsx("div", { className: `flex flex-col ${STACK}`, children: rows.map((row, idx) => (_jsx(Rail, { children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsxs("div", { className: "flex flex-col gap-0.5 min-w-0 shrink-0", children: [by.type.label ? _jsx(FieldLabel, { label: t(by.type.label) }) : null, _jsx("span", { className: "text-sm px-1 py-2", children: fmtOptionLabel(t, { options: byOpts }, String(row[by.key] ?? '')) })] }), _jsx("div", { className: "flex-1 min-w-0", children: _jsx(FlowRow, { items: valueFields.map((sub) => ({
|
|
30
|
+
key: sub.key,
|
|
31
|
+
full: subFull(sub.type),
|
|
32
|
+
node: editing ? (_jsx("div", { className: "flex flex-col gap-0.5 min-w-0", children: _jsx(FieldSlot, { field: sub.type, value: row[sub.key] ?? '', onChange: (v) => update(idx, sub.key, v), label: sub.type.label ? t(sub.type.label) : undefined, mode: "edit", recordCtx: recordCtx }) })) : (_jsxs("div", { className: "flex flex-col gap-0.5 min-w-0", children: [sub.type.label ? _jsx(FieldLabel, { label: t(sub.type.label) }) : null, _jsx(FieldSlot, { field: sub.type, fieldKey: live ? sub.key : undefined, value: row[sub.key] ?? '', onChange: live ? (v) => update(idx, sub.key, v) : undefined, mode: "view", bare: !live, recordCtx: recordCtx })] })),
|
|
33
|
+
})) }) })] }) }, String(row[by.key])))) })] }));
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface GridItem {
|
|
2
|
+
key: string;
|
|
3
|
+
node: React.ReactNode;
|
|
4
|
+
full?: boolean;
|
|
5
|
+
span?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const FlowCtx: import("react").Context<boolean>;
|
|
8
|
+
export declare const useInFlow: () => boolean;
|
|
9
|
+
export type FlowItem = GridItem;
|
|
10
|
+
export declare function getSpanClass(span?: number): string;
|
|
11
|
+
export declare function FlowRow({ items, scroll }: {
|
|
12
|
+
items: FlowItem[];
|
|
13
|
+
scroll?: boolean;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
export const FlowCtx = createContext(false);
|
|
4
|
+
export const useInFlow = () => useContext(FlowCtx);
|
|
5
|
+
export function getSpanClass(span) {
|
|
6
|
+
if (!span || span >= 12)
|
|
7
|
+
return 'col-span-12 min-w-0';
|
|
8
|
+
if (span >= 9)
|
|
9
|
+
return 'col-span-12 @lg:col-span-9 min-w-0';
|
|
10
|
+
if (span >= 8)
|
|
11
|
+
return 'col-span-12 @md:col-span-8 min-w-0';
|
|
12
|
+
if (span >= 6)
|
|
13
|
+
return 'col-span-12 @sm:col-span-6 min-w-0';
|
|
14
|
+
if (span >= 4)
|
|
15
|
+
return 'col-span-12 @sm:col-span-6 @md:col-span-4 min-w-0';
|
|
16
|
+
if (span >= 3)
|
|
17
|
+
return 'col-span-6 @sm:col-span-6 @md:col-span-3 min-w-0';
|
|
18
|
+
if (span === 2)
|
|
19
|
+
return 'col-span-6 @sm:col-span-4 @md:col-span-2 min-w-0';
|
|
20
|
+
return 'col-span-12 @sm:col-span-6 @md:col-span-4 min-w-0';
|
|
21
|
+
}
|
|
22
|
+
export function FlowRow({ items, scroll }) {
|
|
23
|
+
if (scroll) {
|
|
24
|
+
return (_jsx(FlowCtx.Provider, { value: true, children: _jsx("div", { className: "flex gap-x-3 gap-y-2 items-start flex-nowrap overflow-x-auto", children: items.map((it) => (_jsx("div", { className: it.full ? 'basis-full min-w-0' : 'flex-none min-w-0 max-w-[min(16rem,100%)]', children: it.node }, it.key))) }) }));
|
|
25
|
+
}
|
|
26
|
+
return (_jsx(FlowCtx.Provider, { value: true, children: _jsx("div", { className: "@container grid grid-cols-12 gap-x-3.5 gap-y-3 items-start", children: items.map((it) => (_jsx("div", { className: it.full ? 'col-span-12 min-w-0' : getSpanClass(it.span), children: it.node }, it.key))) }) }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { FieldMode } from '../../types.ts';
|
|
3
|
+
export type GroupEditState = {
|
|
4
|
+
mode: FieldMode;
|
|
5
|
+
value: unknown;
|
|
6
|
+
onChange: (v: unknown) => void;
|
|
7
|
+
actions: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export declare function useGroupEdit(mode: FieldMode, value: unknown, onChange: (v: unknown) => void | Promise<string | undefined>): GroupEditState;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useValueEdit } from "../use-field-edit.js";
|
|
3
|
+
import { EditToggle, SaveCancel } from "../chrome.js";
|
|
4
|
+
export function useGroupEdit(mode, value, onChange) {
|
|
5
|
+
const ge = useValueEdit(value, onChange);
|
|
6
|
+
if (mode !== 'view') {
|
|
7
|
+
return { mode, value, onChange: (v) => onChange(v), actions: null };
|
|
8
|
+
}
|
|
9
|
+
if (!ge.editing) {
|
|
10
|
+
return {
|
|
11
|
+
mode: 'view',
|
|
12
|
+
value,
|
|
13
|
+
onChange: (v) => onChange(v),
|
|
14
|
+
actions: _jsx(EditToggle, { scope: "group", onEdit: ge.beginEdit }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
mode: 'edit',
|
|
19
|
+
value: ge.draft,
|
|
20
|
+
onChange: ge.setDraft,
|
|
21
|
+
actions: _jsx(SaveCancel, { size: "xs", busy: ge.busy, onSave: () => ge.commit(), onCancel: ge.cancel }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContainerNode } from '@coffer-org/sdk/fields';
|
|
2
|
+
import type { RecordCtx, FieldMode } from '../../types.ts';
|
|
3
|
+
export declare function GroupField({ group, value, onChange, recordCtx, mode, }: {
|
|
4
|
+
group: ContainerNode;
|
|
5
|
+
value: unknown;
|
|
6
|
+
onChange: (v: unknown) => void;
|
|
7
|
+
recordCtx: RecordCtx;
|
|
8
|
+
mode: FieldMode;
|
|
9
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { isNamedField, isCollectionGroup, isEmbeddedGroup, isStorageGroup } from '@coffer-org/sdk/fields';
|
|
4
|
+
import { resolveRenderer } from "../../registry.js";
|
|
5
|
+
import { FieldSlot } from "../dispatch.js";
|
|
6
|
+
import { useFieldErrors } from "../field-errors.js";
|
|
7
|
+
import { STACK, GroupTitle, Rail, groupIcon } from "../chrome.js";
|
|
8
|
+
import { CollectionGroup, subFull } from "./group.js";
|
|
9
|
+
import { TableGroup } from "./table-group.js";
|
|
10
|
+
import { FlowRow } from "./flow-row.js";
|
|
11
|
+
import { FixedCollection } from "./fixed-collection.js";
|
|
12
|
+
import { useHybridScope } from "../hybrid-scope.js";
|
|
13
|
+
import { SlotProvider } from "../slot.js";
|
|
14
|
+
export function GroupField({ group, value, onChange, recordCtx, mode, }) {
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
const live = useHybridScope() && mode === 'view';
|
|
17
|
+
const errorAt = useFieldErrors();
|
|
18
|
+
const custom = group.kind ? resolveRenderer({ kind: group.kind }) : undefined;
|
|
19
|
+
if (custom) {
|
|
20
|
+
return (_jsx(SlotProvider, { field: group, value: value, commit: onChange, children: _jsx(custom.Page, { el: group, value: value, mode: mode, recordCtx: recordCtx }) }));
|
|
21
|
+
}
|
|
22
|
+
if (isCollectionGroup(group) && group.fixed) {
|
|
23
|
+
return (_jsx(FixedCollection, { group: group, value: value, onChange: (v) => onChange(v), recordCtx: recordCtx, mode: mode }));
|
|
24
|
+
}
|
|
25
|
+
if (isCollectionGroup(group) && group.display === 'scroll') {
|
|
26
|
+
return (_jsx(TableGroup, { group: group, value: value, onChange: (v) => onChange(v), recordCtx: recordCtx, mode: mode }));
|
|
27
|
+
}
|
|
28
|
+
if (isCollectionGroup(group)) {
|
|
29
|
+
return (_jsx(CollectionGroup, { group: group, value: value, onChange: (v) => onChange(v), recordCtx: recordCtx, mode: mode }));
|
|
30
|
+
}
|
|
31
|
+
if (isEmbeddedGroup(group)) {
|
|
32
|
+
const obj = value ?? {};
|
|
33
|
+
const set = (k, v) => onChange({ ...obj, [k]: v });
|
|
34
|
+
const fieldItems = group.fields.filter((f) => isNamedField(f));
|
|
35
|
+
return (_jsxs("fieldset", { className: `flex flex-col min-w-0 ${STACK}`, children: [_jsx(GroupTitle, { as: "legend", label: t(group.label), icon: groupIcon(group) }), _jsx(Rail, { children: _jsx(FlowRow, { items: fieldItems.map((sub) => ({
|
|
36
|
+
key: sub.key,
|
|
37
|
+
full: subFull(sub.type),
|
|
38
|
+
node: (_jsx(FieldSlot, { field: sub.type, fieldKey: live ? sub.key : undefined, value: obj[sub.key] ?? '', onChange: (v) => set(sub.key, v), label: sub.type.label ? t(sub.type.label) : undefined, mode: mode, recordCtx: recordCtx, error: isStorageGroup(group) ? errorAt([group.key, sub.key]) : undefined })),
|
|
39
|
+
})) }) })] }));
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { registerRenderer } from "../../registry.js";
|
|
4
|
+
import { STACK, FieldLabel } from "../chrome.js";
|
|
5
|
+
import { useHybridScope } from "../hybrid-scope.js";
|
|
6
|
+
import { PopoverField } from "../popover-field.js";
|
|
7
|
+
import { useSlot } from "../slot.js";
|
|
8
|
+
import { WeekdayGrid } from "./weekday-grid.js";
|
|
9
|
+
import { UrlWidget } from "./url-widget.js";
|
|
10
|
+
import { ChecklistGroup } from "./checklist-group.js";
|
|
11
|
+
import "./illustrated-group.js";
|
|
12
|
+
import "./attachment-group.js";
|
|
13
|
+
function WeekdayGroupPage({ el, value, mode, bare }) {
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
const { write } = useSlot();
|
|
16
|
+
const group = el;
|
|
17
|
+
const widget = _jsx(WeekdayGrid, { group: group, value: value, onChange: (v) => void write(v), mode: mode });
|
|
18
|
+
if (bare)
|
|
19
|
+
return widget;
|
|
20
|
+
return (_jsxs("div", { className: `group/field flex flex-col min-w-0 ${STACK}`, children: [group.label && _jsx(FieldLabel, { label: t(group.label) }), widget] }));
|
|
21
|
+
}
|
|
22
|
+
const URL_META = { kind: 'url', prim: 'text', column: 'text', label: '', required: false, hints: {} };
|
|
23
|
+
function UrlGroupPage({ el, value, mode, bare }) {
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const slot = useSlot();
|
|
26
|
+
const group = el;
|
|
27
|
+
const hybrid = useHybridScope();
|
|
28
|
+
const widget = (m, v, set) => (_jsx(UrlWidget, { value: v, onChange: (nv) => set(nv), mode: m }));
|
|
29
|
+
if (bare)
|
|
30
|
+
return widget(mode !== 'view' ? 'edit' : 'view', value, (v) => void slot.write(v));
|
|
31
|
+
if (hybrid && slot.writable)
|
|
32
|
+
return (_jsx(PopoverField, { field: URL_META, value: value, label: group.label ? t(group.label) : undefined, geom: "none", width: "w-full", view: (v) => widget('view', v, () => { }), edit: (v, set) => widget('edit', v, set), onCommit: slot.write }));
|
|
33
|
+
return (_jsxs("div", { className: `group/field flex flex-col min-w-0 ${STACK}`, children: [group.label && _jsx(FieldLabel, { label: t(group.label) }), widget(mode !== 'view' ? 'edit' : 'view', value, (v) => void slot.write(v))] }));
|
|
34
|
+
}
|
|
35
|
+
function ChecklistPage({ el, value, recordCtx, mode }) {
|
|
36
|
+
const { write } = useSlot();
|
|
37
|
+
return (_jsx(ChecklistGroup, { group: el, value: value, onChange: (v) => void write(v), recordCtx: recordCtx, mode: mode }));
|
|
38
|
+
}
|
|
39
|
+
registerRenderer({ kinds: ['per-weekday'], layout: 'block', Page: WeekdayGroupPage, editor: 'custom' });
|
|
40
|
+
registerRenderer({ kinds: ['url'], layout: 'block', Page: UrlGroupPage });
|
|
41
|
+
registerRenderer({ kinds: ['checklist'], layout: 'block', Page: ChecklistPage, editor: 'custom' });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ContainerNode, ValueNode } from '@coffer-org/sdk/fields';
|
|
3
|
+
import type { RecordCtx, FieldMode } from '../../types.ts';
|
|
4
|
+
export declare const subFull: (f: ValueNode["type"]) => boolean;
|
|
5
|
+
export type Row = Record<string, unknown>;
|
|
6
|
+
export declare function CollectionWidget({ group, value, onChange, recordCtx, }: {
|
|
7
|
+
group: ContainerNode;
|
|
8
|
+
value: unknown;
|
|
9
|
+
onChange: (v: Row[]) => void;
|
|
10
|
+
recordCtx: RecordCtx;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function CollectionGroup({ group, value, onChange, recordCtx, mode, }: {
|
|
13
|
+
group: ContainerNode;
|
|
14
|
+
value: unknown;
|
|
15
|
+
onChange: (v: Row[]) => void;
|
|
16
|
+
recordCtx: RecordCtx;
|
|
17
|
+
mode: FieldMode;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
export declare function CollectionView({ group, value, onChange, recordCtx, actions, editable, }: {
|
|
20
|
+
group: ContainerNode;
|
|
21
|
+
value: unknown;
|
|
22
|
+
onChange: (v: Row[]) => void;
|
|
23
|
+
recordCtx: RecordCtx;
|
|
24
|
+
actions?: ReactNode;
|
|
25
|
+
editable?: boolean;
|
|
26
|
+
}): import("react").JSX.Element;
|