@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,104 @@
|
|
|
1
|
+
export const LIVE_ENABLED = new Set(['popover', 'heavy']);
|
|
2
|
+
export const NON_FIELD_KINDS = new Set(['button', 'divider', 'info']);
|
|
3
|
+
export const BY_KIND = {
|
|
4
|
+
text: 'popover',
|
|
5
|
+
smalltext: 'popover',
|
|
6
|
+
textarea: 'popover',
|
|
7
|
+
title: 'popover',
|
|
8
|
+
slug: 'popover',
|
|
9
|
+
snippet: 'popover',
|
|
10
|
+
email: 'popover',
|
|
11
|
+
tel: 'popover',
|
|
12
|
+
password: 'popover',
|
|
13
|
+
url: 'popover',
|
|
14
|
+
link: 'popover',
|
|
15
|
+
number: 'popover',
|
|
16
|
+
amount: 'popover',
|
|
17
|
+
money: 'popover',
|
|
18
|
+
weight: 'popover',
|
|
19
|
+
unit: 'popover',
|
|
20
|
+
dataSize: 'popover',
|
|
21
|
+
duration: 'popover',
|
|
22
|
+
numberRange: 'popover',
|
|
23
|
+
realRange: 'popover',
|
|
24
|
+
dimensions: 'popover',
|
|
25
|
+
measured: 'popover',
|
|
26
|
+
geo: 'popover',
|
|
27
|
+
localFile: 'popover',
|
|
28
|
+
localDir: 'popover',
|
|
29
|
+
ip: 'popover',
|
|
30
|
+
cidr: 'popover',
|
|
31
|
+
scalar: 'popover',
|
|
32
|
+
boolean: 'popover',
|
|
33
|
+
triState: 'popover',
|
|
34
|
+
rating: 'popover',
|
|
35
|
+
check: 'popover',
|
|
36
|
+
color: 'popover',
|
|
37
|
+
select: 'popover',
|
|
38
|
+
tag: 'popover',
|
|
39
|
+
relation: 'popover',
|
|
40
|
+
date: 'popover',
|
|
41
|
+
datetime: 'popover',
|
|
42
|
+
time: 'popover',
|
|
43
|
+
period: 'popover',
|
|
44
|
+
reminder: 'popover',
|
|
45
|
+
source: 'popover',
|
|
46
|
+
markdown: 'popover',
|
|
47
|
+
code: 'popover',
|
|
48
|
+
json: 'popover',
|
|
49
|
+
i18n: 'popover',
|
|
50
|
+
file: 'popover',
|
|
51
|
+
embed: 'popover',
|
|
52
|
+
document: 'popover',
|
|
53
|
+
image: 'popover',
|
|
54
|
+
media: 'popover',
|
|
55
|
+
avatar: 'popover',
|
|
56
|
+
cover: 'popover',
|
|
57
|
+
poster: 'popover',
|
|
58
|
+
audio: 'popover',
|
|
59
|
+
video: 'popover',
|
|
60
|
+
collection: 'heavy',
|
|
61
|
+
embedded: 'heavy',
|
|
62
|
+
checklist: 'heavy',
|
|
63
|
+
illustrated: 'heavy',
|
|
64
|
+
illustratedList: 'heavy',
|
|
65
|
+
'per-weekday': 'heavy',
|
|
66
|
+
group: 'heavy',
|
|
67
|
+
block: 'heavy',
|
|
68
|
+
calendar: 'heavy',
|
|
69
|
+
journal: 'heavy',
|
|
70
|
+
manifest: 'heavy',
|
|
71
|
+
table: 'heavy',
|
|
72
|
+
internalApiToken: 'heavy',
|
|
73
|
+
internalOauthGrants: 'heavy',
|
|
74
|
+
};
|
|
75
|
+
const BY_PRIM = {
|
|
76
|
+
text: 'popover',
|
|
77
|
+
number: 'popover',
|
|
78
|
+
measured: 'popover',
|
|
79
|
+
money: 'popover',
|
|
80
|
+
geo: 'popover',
|
|
81
|
+
lookup: 'popover',
|
|
82
|
+
checkbox: 'popover',
|
|
83
|
+
triState: 'popover',
|
|
84
|
+
check: 'popover',
|
|
85
|
+
'per-weekday': 'heavy',
|
|
86
|
+
select: 'popover',
|
|
87
|
+
relation: 'popover',
|
|
88
|
+
date: 'popover',
|
|
89
|
+
time: 'popover',
|
|
90
|
+
datetime: 'popover',
|
|
91
|
+
json: 'popover',
|
|
92
|
+
code: 'popover',
|
|
93
|
+
file: 'popover',
|
|
94
|
+
};
|
|
95
|
+
export function defaultLiveKind(field) {
|
|
96
|
+
const hinted = field.hints?.['live'];
|
|
97
|
+
if (hinted === 'popover' || hinted === 'heavy')
|
|
98
|
+
return hinted;
|
|
99
|
+
return BY_KIND[field.kind] ?? BY_PRIM[field.prim] ?? 'popover';
|
|
100
|
+
}
|
|
101
|
+
export function liveKind(field) {
|
|
102
|
+
const k = defaultLiveKind(field);
|
|
103
|
+
return LIVE_ENABLED.has(k) ? k : null;
|
|
104
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { marked } from 'marked';
|
|
3
|
+
import DOMPurify from 'dompurify';
|
|
4
|
+
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
|
|
5
|
+
if (node.tagName === 'A') {
|
|
6
|
+
node.setAttribute('target', '_blank');
|
|
7
|
+
node.setAttribute('rel', 'noopener noreferrer');
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
export function markdownToSafeHtml(src) {
|
|
11
|
+
const raw = marked.parse(src, { async: false });
|
|
12
|
+
return DOMPurify.sanitize(raw);
|
|
13
|
+
}
|
|
14
|
+
export function MarkdownView({ value }) {
|
|
15
|
+
return _jsx("div", { className: "md-static", dangerouslySetInnerHTML: { __html: markdownToSafeHtml(value) } });
|
|
16
|
+
}
|
|
17
|
+
export default MarkdownView;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export declare function asArray(value: unknown): unknown[];
|
|
3
|
+
export declare function firstOf(value: unknown): unknown;
|
|
4
|
+
export declare function MultipleField({ value, onChange, renderItem, renderEditItem, editing, }: {
|
|
5
|
+
value: unknown;
|
|
6
|
+
onChange?: (v: unknown) => void | Promise<string | undefined>;
|
|
7
|
+
renderItem: (v: unknown, i: number) => ReactNode;
|
|
8
|
+
renderEditItem: (v: unknown, set: (nv: unknown) => void, i: number) => ReactNode;
|
|
9
|
+
editing: boolean;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { parseJSON } from "../lib/json.js";
|
|
3
|
+
import { AddBtn, RemoveBtn } from "./shared.js";
|
|
4
|
+
export function asArray(value) {
|
|
5
|
+
if (Array.isArray(value))
|
|
6
|
+
return value;
|
|
7
|
+
if (typeof value === 'string')
|
|
8
|
+
return parseJSON(value, []);
|
|
9
|
+
return value == null || value === '' ? [] : [value];
|
|
10
|
+
}
|
|
11
|
+
export function firstOf(value) {
|
|
12
|
+
const a = asArray(value);
|
|
13
|
+
return a.length ? a[0] : '';
|
|
14
|
+
}
|
|
15
|
+
export function MultipleField({ value, onChange, renderItem, renderEditItem, editing, }) {
|
|
16
|
+
const arr = asArray(value);
|
|
17
|
+
if (!editing) {
|
|
18
|
+
if (!arr.length)
|
|
19
|
+
return _jsx("span", { className: "text-muted", children: "\u2014" });
|
|
20
|
+
return (_jsx("div", { className: "flex flex-col gap-1", children: arr.map((v, i) => (_jsx("div", { children: renderItem(v, i) }, i))) }));
|
|
21
|
+
}
|
|
22
|
+
const setAt = (i, nv) => onChange?.(arr.map((x, j) => (j === i ? nv : x)));
|
|
23
|
+
const add = () => onChange?.([...arr, '']);
|
|
24
|
+
const removeAt = (i) => onChange?.(arr.filter((_, j) => j !== i));
|
|
25
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [arr.map((v, i) => (_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: renderEditItem(v, (nv) => setAt(i, nv), i) }), _jsx(RemoveBtn, { onClick: () => removeAt(i) })] }, i))), _jsx(AddBtn, { onClick: add, children: "Add" })] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const Dash: () => React.JSX.Element;
|
|
3
|
+
export declare function RemoveBtn({ onClick, className }: {
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
className?: string;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
export declare function Chip({ children, className, style, onRemove, }: {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
onRemove?: () => void;
|
|
12
|
+
}): React.JSX.Element;
|
|
13
|
+
export declare function ChipList({ children }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}): React.JSX.Element;
|
|
16
|
+
export declare function MultipleChips({ items, content, chipClassName, chipStyle, onRemove, editor, emptyDash, }: {
|
|
17
|
+
items: unknown[];
|
|
18
|
+
content: (item: unknown, idx: number) => React.ReactNode;
|
|
19
|
+
chipClassName?: (item: unknown, idx: number) => string;
|
|
20
|
+
chipStyle?: (item: unknown, idx: number) => React.CSSProperties;
|
|
21
|
+
onRemove?: (idx: number) => void;
|
|
22
|
+
editor?: React.ReactNode;
|
|
23
|
+
emptyDash?: boolean;
|
|
24
|
+
}): React.JSX.Element | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { X } from 'lucide-react';
|
|
3
|
+
import { CHIP_CLS } from "../components/ui/chip-cls.js";
|
|
4
|
+
export const Dash = () => _jsx("span", { className: "text-sm text-muted/50 select-none", children: "\u2014" });
|
|
5
|
+
export function RemoveBtn({ onClick, className }) {
|
|
6
|
+
return (_jsx("button", { type: "button", onClick: onClick, "aria-label": "remove", className: `inline-flex shrink-0 items-center text-muted transition-colors hover:text-danger ${className ?? ''}`, children: _jsx(X, { size: 13 }) }));
|
|
7
|
+
}
|
|
8
|
+
export function Chip({ children, className, style, onRemove, }) {
|
|
9
|
+
return (_jsxs("span", { className: `${CHIP_CLS} ${className ?? ''}`, style: style, children: [children, onRemove && _jsx(RemoveBtn, { onClick: onRemove })] }));
|
|
10
|
+
}
|
|
11
|
+
export function ChipList({ children }) {
|
|
12
|
+
return _jsx("div", { className: "flex flex-wrap gap-1.5", children: children });
|
|
13
|
+
}
|
|
14
|
+
export function MultipleChips({ items, content, chipClassName, chipStyle, onRemove, editor, emptyDash = true, }) {
|
|
15
|
+
if (!items.length && !editor)
|
|
16
|
+
return emptyDash ? _jsx(Dash, {}) : null;
|
|
17
|
+
return (_jsxs("div", { className: `flex flex-col gap-2 ${editor ? 'px-2' : ''}`, children: [items.length > 0 && (_jsx(ChipList, { children: items.map((it, idx) => (_jsx(Chip, { className: chipClassName?.(it, idx), style: chipStyle?.(it, idx), onRemove: onRemove ? () => onRemove(idx) : undefined, children: content(it, idx) }, idx))) })), editor] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { FieldMeta, OptionItem } from '@coffer-org/sdk/fields';
|
|
3
|
+
export type ListItem = OptionItem & {
|
|
4
|
+
node?: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export declare function OptionList({ field, options, value, multiple, literal, autoFocusSearch, search, onPick, }: {
|
|
7
|
+
field?: FieldMeta;
|
|
8
|
+
options: ListItem[];
|
|
9
|
+
value: unknown;
|
|
10
|
+
multiple: boolean;
|
|
11
|
+
literal?: boolean;
|
|
12
|
+
autoFocusSearch?: boolean;
|
|
13
|
+
search?: boolean;
|
|
14
|
+
onPick: (next: unknown) => void;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Check } from 'lucide-react';
|
|
5
|
+
import { resolveRenderer } from "../registry.js";
|
|
6
|
+
import { OptionIconView } from "../components/ui/option-icon.js";
|
|
7
|
+
const SEARCH_THRESHOLD = 8;
|
|
8
|
+
export function OptionList({ field, options, value, multiple, literal, autoFocusSearch = true, search, onPick, }) {
|
|
9
|
+
const Value = field ? resolveRenderer(field)?.Value : undefined;
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const [query, setQuery] = useState('');
|
|
12
|
+
const listRef = useRef(null);
|
|
13
|
+
const title = (o) => (literal ? o.title : t(o.title));
|
|
14
|
+
const selected = useMemo(() => {
|
|
15
|
+
if (!multiple)
|
|
16
|
+
return value == null || value === '' ? [] : [String(value)];
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
return value.map(String);
|
|
19
|
+
return [];
|
|
20
|
+
}, [value, multiple]);
|
|
21
|
+
const shown = useMemo(() => {
|
|
22
|
+
const q = query.trim().toLowerCase();
|
|
23
|
+
if (!q)
|
|
24
|
+
return options;
|
|
25
|
+
return options.filter((o) => title(o).toLowerCase().includes(q) ||
|
|
26
|
+
o.value.toLowerCase().includes(q) ||
|
|
27
|
+
(o.subtitle?.toLowerCase().includes(q) ?? false));
|
|
28
|
+
}, [options, query, t, literal]);
|
|
29
|
+
function pick(v) {
|
|
30
|
+
if (!multiple) {
|
|
31
|
+
onPick(v);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
onPick(selected.includes(v) ? selected.filter((s) => s !== v) : [...selected, v]);
|
|
35
|
+
}
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const box = listRef.current;
|
|
38
|
+
const on = box?.querySelector('[aria-selected="true"]');
|
|
39
|
+
if (!box || !on)
|
|
40
|
+
return;
|
|
41
|
+
box.scrollTop = Math.max(0, on.offsetTop - box.clientHeight / 2 + on.offsetHeight / 2);
|
|
42
|
+
}, []);
|
|
43
|
+
return (_jsxs("div", { className: "flex flex-col gap-1 min-w-0", children: [(search ?? options.length > SEARCH_THRESHOLD) && (_jsx("input", { autoFocus: autoFocusSearch, value: query, onChange: (e) => setQuery(e.target.value), placeholder: t('form.search'), "aria-label": t('form.search'), className: "mb-1 text-sm" })), _jsxs("div", { ref: listRef, role: "listbox", "aria-multiselectable": multiple, className: "flex max-h-72 flex-col overflow-y-auto", children: [shown.length === 0 && _jsx("span", { className: "px-2 py-1.5 text-sm text-muted", children: t('common.empty') }), shown.map((o) => {
|
|
44
|
+
const on = selected.includes(o.value);
|
|
45
|
+
return (_jsxs("button", { type: "button", role: "option", "aria-selected": on, onClick: () => pick(o.value), className: "flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-elevated focus-visible:bg-elevated focus-visible:outline-none", children: [o.node ? (_jsx("span", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: o.node })) : Value && field ? (_jsx("span", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: _jsx(Value, { field: field, value: o.value }) })) : (_jsxs(_Fragment, { children: [o.icon && _jsx(OptionIconView, { icon: o.icon, size: "xs" }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: title(o) }), o.subtitle && o.subtitle !== title(o) && (_jsx("span", { className: "shrink-0 text-xs text-muted", children: o.subtitle }))] })), on && _jsx(Check, { size: 14, className: "shrink-0 text-accent" })] }, o.value));
|
|
46
|
+
})] })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { FieldMeta, OptionItem } from '@coffer-org/sdk/fields';
|
|
3
|
+
import type { FieldKey, FieldKeyCtx } from '../types.ts';
|
|
4
|
+
export { fieldOptions } from '../lib/format.ts';
|
|
5
|
+
export declare function OptionValue({ field, value }: {
|
|
6
|
+
field: FieldMeta;
|
|
7
|
+
value: unknown;
|
|
8
|
+
}): ReactNode;
|
|
9
|
+
export declare function optionChipProps(field: Pick<FieldMeta, 'options' | 'hints'>): {
|
|
10
|
+
chipClassName?: () => string;
|
|
11
|
+
chipStyle?: (item: unknown) => CSSProperties;
|
|
12
|
+
};
|
|
13
|
+
export declare function optionKeys(value: unknown, field: FieldMeta, ctx: FieldKeyCtx): FieldKey[];
|
|
14
|
+
export declare function OptionInput({ field, value, onChange, offered, exclude, }: {
|
|
15
|
+
field: FieldMeta;
|
|
16
|
+
value: unknown;
|
|
17
|
+
onChange: (v: string | string[]) => void;
|
|
18
|
+
offered?: OptionItem[];
|
|
19
|
+
exclude?: string[];
|
|
20
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { hasOptions } from '@coffer-org/sdk/fields';
|
|
3
|
+
import { OptionIconView } from "../components/ui/option-icon.js";
|
|
4
|
+
import { Combobox, ChipsCombobox } from "../components/ui/select-combobox.js";
|
|
5
|
+
import { optionLabel, fieldOptions } from "../lib/format.js";
|
|
6
|
+
import { catColor } from "../lib/cat-color.js";
|
|
7
|
+
import { parseJSON } from "../lib/json.js";
|
|
8
|
+
import { toComboItems, useTranslation } from "./shared.js";
|
|
9
|
+
export { fieldOptions } from "../lib/format.js";
|
|
10
|
+
export function OptionValue({ field, value }) {
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const str = String(value ?? '');
|
|
13
|
+
const opt = fieldOptions(field).find((o) => o.value === str);
|
|
14
|
+
const label = opt ? t(opt.title) : str;
|
|
15
|
+
return (_jsxs("span", { className: "inline-flex min-w-0 items-center gap-1.5", children: [opt?.icon && _jsx(OptionIconView, { icon: opt.icon, size: "xs" }), _jsx("span", { className: "min-w-0 truncate", children: label }), opt?.subtitle && opt.subtitle !== label && _jsx("span", { className: "text-muted text-xs shrink-0", children: opt.subtitle })] }));
|
|
16
|
+
}
|
|
17
|
+
export function optionChipProps(field) {
|
|
18
|
+
if (!hasOptions(field))
|
|
19
|
+
return {};
|
|
20
|
+
return {
|
|
21
|
+
chipClassName: () => 'cat-chip',
|
|
22
|
+
chipStyle: (item) => ({ '--cat': catColor(String(item)) }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function optionKeys(value, field, ctx) {
|
|
26
|
+
if (value == null || value === '')
|
|
27
|
+
return [];
|
|
28
|
+
const code = String(value);
|
|
29
|
+
const label = optionLabel(ctx.t, field, code);
|
|
30
|
+
return [{ value: code, rawValue: value, label, sort: label }];
|
|
31
|
+
}
|
|
32
|
+
export function OptionInput({ field, value, onChange, offered, exclude, }) {
|
|
33
|
+
const { t } = useTranslation();
|
|
34
|
+
const all = offered ?? fieldOptions(field);
|
|
35
|
+
if (field.hints['multiple'] === true) {
|
|
36
|
+
const raw = Array.isArray(value) ? value : parseJSON(value, []);
|
|
37
|
+
return (_jsx(ChipsCombobox, { selected: raw.map(String), items: toComboItems(all, t), onChange: (next) => onChange(next), placeholder: t('form.search'), chipClassName: () => 'cat-chip', chipStyle: (v) => ({ '--cat': catColor(v) }) }));
|
|
38
|
+
}
|
|
39
|
+
const opts = exclude?.length ? all.filter((o) => o.value === value || !exclude.includes(o.value)) : all;
|
|
40
|
+
return (_jsx(Combobox, { value: typeof value === 'string' ? value : '', onChange: onChange, items: toComboItems(opts, t), placeholder: t('form.search') }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export declare function registerOpenPicker(): () => void;
|
|
3
|
+
export declare function useAnyPickerOpen(): boolean;
|
|
4
|
+
export declare function PickerScrimArea({ children }: {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function useRegisterPicker(isOpen: boolean): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
3
|
+
let open = 0;
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
const emit = () => listeners.forEach((l) => l());
|
|
6
|
+
export function registerOpenPicker() {
|
|
7
|
+
open += 1;
|
|
8
|
+
emit();
|
|
9
|
+
let done = false;
|
|
10
|
+
return () => {
|
|
11
|
+
if (done)
|
|
12
|
+
return;
|
|
13
|
+
done = true;
|
|
14
|
+
open -= 1;
|
|
15
|
+
emit();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function subscribe(l) {
|
|
19
|
+
listeners.add(l);
|
|
20
|
+
return () => listeners.delete(l);
|
|
21
|
+
}
|
|
22
|
+
const snapshot = () => open > 0;
|
|
23
|
+
export function useAnyPickerOpen() {
|
|
24
|
+
return useSyncExternalStore(subscribe, snapshot, () => false);
|
|
25
|
+
}
|
|
26
|
+
export function PickerScrimArea({ children }) {
|
|
27
|
+
const covered = useAnyPickerOpen();
|
|
28
|
+
return (_jsxs("div", { className: "relative min-w-0 flex-1", children: [children, covered && _jsx("div", { className: "absolute inset-0 z-40", "data-testid": "picker-scrim", "aria-hidden": true })] }));
|
|
29
|
+
}
|
|
30
|
+
export function useRegisterPicker(isOpen) {
|
|
31
|
+
useEffect(() => (isOpen ? registerOpenPicker() : undefined), [isOpen]);
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
const PickerSurfaceContext = createContext(false);
|
|
4
|
+
export function PickerSurface({ children }) {
|
|
5
|
+
return _jsx(PickerSurfaceContext.Provider, { value: true, children: children });
|
|
6
|
+
}
|
|
7
|
+
export function useOnPickerSurface() {
|
|
8
|
+
return useContext(PickerSurfaceContext);
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type FieldMeta, type OptionItem } from '@coffer-org/sdk/fields';
|
|
3
|
+
import type { BoxGeom } from '../types.ts';
|
|
4
|
+
export declare function PopoverField({ field, value, label, required, error, geom, view, edit, pickerOptions, onCommit, width, }: {
|
|
5
|
+
field: FieldMeta;
|
|
6
|
+
value: unknown;
|
|
7
|
+
label?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
geom: BoxGeom;
|
|
11
|
+
view: (value: unknown, commit: (v: unknown) => void) => ReactNode;
|
|
12
|
+
edit: (value: unknown, onChange: (v: unknown) => void) => ReactNode;
|
|
13
|
+
pickerOptions?: OptionItem[];
|
|
14
|
+
onCommit: (v: unknown) => void | Promise<string | undefined>;
|
|
15
|
+
width?: string;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { wrapKey } from '@coffer-org/sdk/fields';
|
|
6
|
+
import { fieldLayout, resolveRenderer } from "../registry.js";
|
|
7
|
+
import { Popover, PopoverAnchor, PopoverArrow, PopoverContent } from "../components/ui/popover.js";
|
|
8
|
+
import { Dialog, DialogBody, DialogContent, DialogHeader, DialogTitle } from "../components/ui/dialog.js";
|
|
9
|
+
import { Button } from "../components/ui/button.js";
|
|
10
|
+
import { Plus } from 'lucide-react';
|
|
11
|
+
import { useMinWidth } from "../hooks/use-media-query.js";
|
|
12
|
+
import { FieldLabel, FieldError, FieldBox } from "./chrome.js";
|
|
13
|
+
import { makeIssueText } from "./field-errors.js";
|
|
14
|
+
import { normalizeValue } from "./use-field-edit.js";
|
|
15
|
+
import { focusInPopup } from "./field-frame.js";
|
|
16
|
+
import { editorMode } from "./editor-mode.js";
|
|
17
|
+
import { useRegisterPicker } from "./picker-scrim.js";
|
|
18
|
+
import { useFieldAddress } from "./field-address.js";
|
|
19
|
+
import { PickerSurface } from "./picker-surface.js";
|
|
20
|
+
import { OptionList } from "./option-list.js";
|
|
21
|
+
import { fieldOptions } from "./option-value.js";
|
|
22
|
+
import { hasValue } from "./shared.js";
|
|
23
|
+
import { parseJSON } from "../lib/json.js";
|
|
24
|
+
import { makeWriter } from "./write.js";
|
|
25
|
+
import { SlotProvider } from "./slot.js";
|
|
26
|
+
function Picker({ field, validateWith, trigger, seed, options, listMultiple, pickDecides, showInput, size, label, edit, build, onCommit, onDelete, removeLabel, }) {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const wide = useMinWidth('sm', 640);
|
|
29
|
+
const [open, setOpen] = useState(false);
|
|
30
|
+
const [draft, setDraft] = useState(seed);
|
|
31
|
+
const [busy, setBusy] = useState(false);
|
|
32
|
+
const [localError, setLocalError] = useState();
|
|
33
|
+
const bodyRef = useRef(null);
|
|
34
|
+
useRegisterPicker(open);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!open)
|
|
37
|
+
return;
|
|
38
|
+
const id = requestAnimationFrame(() => {
|
|
39
|
+
const el = bodyRef.current?.querySelector('input:not([type="hidden"]), textarea, [contenteditable="true"]');
|
|
40
|
+
el?.focus();
|
|
41
|
+
});
|
|
42
|
+
return () => cancelAnimationFrame(id);
|
|
43
|
+
}, [open]);
|
|
44
|
+
function start() {
|
|
45
|
+
setDraft(seed);
|
|
46
|
+
setLocalError(undefined);
|
|
47
|
+
setOpen(true);
|
|
48
|
+
}
|
|
49
|
+
function cancel() {
|
|
50
|
+
setLocalError(undefined);
|
|
51
|
+
setOpen(false);
|
|
52
|
+
}
|
|
53
|
+
async function write(next) {
|
|
54
|
+
setBusy(true);
|
|
55
|
+
const err = await makeWriter(field, onCommit, makeIssueText(t), validateWith)(next);
|
|
56
|
+
setBusy(false);
|
|
57
|
+
if (err) {
|
|
58
|
+
setLocalError(err);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setLocalError(undefined);
|
|
62
|
+
setOpen(false);
|
|
63
|
+
}
|
|
64
|
+
function pick(next) {
|
|
65
|
+
if (pickDecides)
|
|
66
|
+
void write(build(next));
|
|
67
|
+
else
|
|
68
|
+
setDraft(next);
|
|
69
|
+
}
|
|
70
|
+
const Custom = resolveRenderer(field)?.Picker;
|
|
71
|
+
const body = (_jsxs(PickerSurface, { children: [_jsx("div", { ref: bodyRef, className: `flex min-w-0 flex-col gap-2 ${size === 'modal' ? 'min-h-0 flex-1' : ''}`, children: Custom ? (_jsx(Custom, { field: field, draft: draft, setDraft: setDraft, options: options, save: (v) => void write(build(v === undefined ? draft : v)), cancel: cancel, remove: onDelete ? () => void write(onDelete()) : undefined, removeLabel: removeLabel })) : (_jsxs(_Fragment, { children: [showInput &&
|
|
72
|
+
edit(normalizeValue(field, draft), setDraft), options && (_jsx(OptionList, { field: field, options: options, value: draft, multiple: listMultiple, onPick: pick }))] })) }), _jsx(FieldError, { error: localError }), !Custom && (showInput || onDelete) && (_jsxs("div", { className: "mt-2 flex items-center justify-end gap-2 border-t border-border pt-2", children: [onDelete && (_jsx(Button, { type: "button", variant: "destructiveOutline", size: "sm", className: "mr-auto", disabled: busy, onClick: () => void write(onDelete()), children: removeLabel })), showInput && (_jsx(Button, { type: "button", size: "sm", disabled: busy, onClick: () => void write(build(draft)), children: t('actions.save') }))] }))] }));
|
|
73
|
+
const asWindow = size === 'modal' || !wide;
|
|
74
|
+
const panelWidth = size === 'large' ? 'w-[min(32rem,calc(100vw-2rem))]' : 'w-72';
|
|
75
|
+
const anchored = (_jsxs(Popover, { open: open, onOpenChange: (o) => (o ? start() : cancel()), children: [_jsxs(TriggerBox, { open: open, label: label, onOpen: start, children: [trigger, _jsx(PopoverAnchor, { asChild: true, children: _jsx("span", { "aria-hidden": true, className: `pointer-events-none absolute inset-y-0 left-0 max-w-full ${panelWidth}` }) })] }), _jsxs(PopoverContent, { align: "start", className: `${panelWidth} p-2`, onInteractOutside: (e) => {
|
|
76
|
+
if (focusInPopup(e.target))
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
}, onEscapeKeyDown: cancel, children: [_jsx(PopoverArrow, {}), body] })] }));
|
|
79
|
+
if (!asWindow)
|
|
80
|
+
return anchored;
|
|
81
|
+
return (_jsxs(_Fragment, { children: [_jsx(TriggerBox, { open: open, label: label, onOpen: start, children: trigger }), _jsx(Dialog, { open: open, onOpenChange: (o) => (o ? start() : cancel()), children: _jsxs(DialogContent, { onEscapeKeyDown: cancel, className: "h-[88dvh] md:h-[min(80dvh,52rem)] md:max-w-5xl md:overflow-hidden", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: label ?? '' }) }), _jsx(DialogBody, { children: body })] }) })] }));
|
|
82
|
+
}
|
|
83
|
+
function TriggerBox({ open, label, onOpen, children, ...rest }) {
|
|
84
|
+
return (_jsx("div", { ...rest, role: "button", tabIndex: 0, "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": label, className: "relative min-w-0 cursor-pointer rounded-lg border border-transparent focus-visible:border-accent focus-visible:outline-none", onClick: (e) => {
|
|
85
|
+
const inner = e.target.closest('a,button,[role="button"],audio,video,input,label');
|
|
86
|
+
if (inner && inner !== e.currentTarget)
|
|
87
|
+
return;
|
|
88
|
+
onOpen();
|
|
89
|
+
}, onKeyDown: (e) => {
|
|
90
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
onOpen();
|
|
93
|
+
}
|
|
94
|
+
}, children: children }));
|
|
95
|
+
}
|
|
96
|
+
export function PopoverField({ field, value, label, required, error, geom, view, edit, pickerOptions, onCommit, width = 'w-64', }) {
|
|
97
|
+
const { t } = useTranslation();
|
|
98
|
+
const R = resolveRenderer(field);
|
|
99
|
+
const declared = R?.pickerSize;
|
|
100
|
+
const size = editorMode(field) === 'modal'
|
|
101
|
+
? 'modal'
|
|
102
|
+
: ((typeof declared === 'function' ? declared(field) : declared) ??
|
|
103
|
+
(fieldLayout(field) === 'block' || geom === 'textarea' ? 'large' : 'small'));
|
|
104
|
+
const multi = field.hints['multiple'] === true;
|
|
105
|
+
const opts = pickerOptions ?? fieldOptions(field);
|
|
106
|
+
const options = opts?.length ? opts : undefined;
|
|
107
|
+
const showInput = !(options && field.strict);
|
|
108
|
+
const Value = R?.Value;
|
|
109
|
+
const perValue = multi && Value;
|
|
110
|
+
const address = useFieldAddress();
|
|
111
|
+
const scalarField = useMemo(() => ({ ...field, hints: { ...field.hints, multiple: false }, json: undefined }), [field]);
|
|
112
|
+
const freeField = useMemo(() => ({ ...field, options: undefined, hints: { ...field.hints, source: null, suggestions: undefined } }), [field]);
|
|
113
|
+
const freeScalarField = useMemo(() => ({ ...freeField, hints: { ...freeField.hints, multiple: false }, json: undefined }), [freeField]);
|
|
114
|
+
const bareEdit = (f, v, onChange) => R ? (_jsx(SlotProvider, { field: wrapKey('value', {}, f), value: v, commit: onChange, children: _jsx(R.Page, { field: f, value: v, mode: "edit", bare: true, recordCtx: address.recordCtx ?? { library: '', shelf: '', recordId: null } }) })) : (edit(v, onChange));
|
|
115
|
+
const scalarEdit = (v, onChange) => bareEdit(freeScalarField, v, onChange);
|
|
116
|
+
const inputEdit = options ? (v, onChange) => bareEdit(freeField, v, onChange) : edit;
|
|
117
|
+
const emphasis = field.hints['emphasis'];
|
|
118
|
+
const noLabel = field.hints['noLabel'] === true || label === undefined;
|
|
119
|
+
const inplace = editorMode(field) === 'inplace' && !perValue;
|
|
120
|
+
const triggerDisplay = view;
|
|
121
|
+
const shell = (children) => {
|
|
122
|
+
if (emphasis === 'muted')
|
|
123
|
+
return (_jsxs("div", { className: "group/field grid grid-cols-[110px_1fr] items-center gap-x-3 text-xs text-muted min-w-0", children: [_jsx("span", { children: label }), _jsx("span", { className: "min-w-0", children: children }), _jsx(FieldError, { error: error })] }));
|
|
124
|
+
if (noLabel)
|
|
125
|
+
return (_jsxs("div", { className: "group/field relative min-w-0", children: [children, _jsx(FieldError, { error: error })] }));
|
|
126
|
+
return (_jsxs("div", { className: `group/field relative ${width}`, children: [_jsx(FieldLabel, { label: label, required: required }), children, _jsx(FieldError, { error: error })] }));
|
|
127
|
+
};
|
|
128
|
+
if (inplace) {
|
|
129
|
+
return shell(_jsx(FieldBox, { geom: geom, field: field, children: view(value, (v) => void onCommit(v)) }));
|
|
130
|
+
}
|
|
131
|
+
if (perValue) {
|
|
132
|
+
const items = Array.isArray(value) ? value : parseJSON(value, []);
|
|
133
|
+
const at = (idx, next) => items.map((it, i) => (i === idx ? next : it));
|
|
134
|
+
const without = (idx) => {
|
|
135
|
+
const left = items.filter((_, i) => i !== idx);
|
|
136
|
+
return left.length ? left : '';
|
|
137
|
+
};
|
|
138
|
+
const one = {
|
|
139
|
+
field: scalarField,
|
|
140
|
+
edit: scalarEdit,
|
|
141
|
+
options,
|
|
142
|
+
listMultiple: false,
|
|
143
|
+
pickDecides: true,
|
|
144
|
+
showInput,
|
|
145
|
+
size,
|
|
146
|
+
label,
|
|
147
|
+
removeLabel: t('actions.delete'),
|
|
148
|
+
};
|
|
149
|
+
return shell(_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1.5", children: [items.map((item, idx) => (_createElement(Picker, { ...one, key: `${String(item)}-${idx}`, validateWith: field, seed: item, build: (d) => at(idx, d), onDelete: () => without(idx), onCommit: onCommit, trigger: _jsx("span", { className: "inline-flex min-w-0 items-center gap-1.5 rounded-full border border-border px-2 py-0.5 text-sm", children: _jsx(Value, { field: field, value: item }) }) }))), _jsx(Picker, { ...one, validateWith: field, seed: "", build: (d) => [...items, d], onCommit: onCommit, trigger: _jsx("span", { className: "inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-sm text-muted", title: t('actions.add'), children: _jsx(Plus, { size: 14 }) }) })] }));
|
|
150
|
+
}
|
|
151
|
+
const clearable = !multi && !field.required && !required && hasValue(value);
|
|
152
|
+
return shell(_jsx(Picker, { field: field, label: label, size: size, options: options, listMultiple: multi, pickDecides: !multi, showInput: showInput, seed: value, edit: inputEdit, build: (d) => d, onCommit: onCommit, onDelete: clearable ? () => '' : undefined, removeLabel: t('actions.clear'), trigger: _jsx(FieldBox, { geom: geom, field: field, children: triggerDisplay(value, (v) => void onCommit(v)) }) }));
|
|
153
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type RunFn = (fn: () => Promise<string | undefined> | string | undefined | void) => Promise<string | undefined>;
|
|
3
|
+
type Ctx = {
|
|
4
|
+
saving: boolean;
|
|
5
|
+
run: RunFn;
|
|
6
|
+
};
|
|
7
|
+
export declare function RecordSaveProvider({ children }: {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function useRecordSave(): Ctx;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { toast } from 'sonner';
|
|
5
|
+
const RecordSaveContext = createContext(null);
|
|
6
|
+
export function RecordSaveProvider({ children }) {
|
|
7
|
+
const { t } = useTranslation();
|
|
8
|
+
const [count, setCount] = useState(0);
|
|
9
|
+
const run = useCallback(async (fn) => {
|
|
10
|
+
const tid = toast.loading(t('save.saving'));
|
|
11
|
+
setCount((c) => c + 1);
|
|
12
|
+
try {
|
|
13
|
+
const r = await fn();
|
|
14
|
+
const msg = typeof r === 'string' ? r : undefined;
|
|
15
|
+
if (msg)
|
|
16
|
+
toast.error(msg, { id: tid });
|
|
17
|
+
else
|
|
18
|
+
toast.success(t('save.done'), { id: tid });
|
|
19
|
+
return msg;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
toast.error(t('save.failed'), { id: tid });
|
|
23
|
+
return t('save.failed');
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
setCount((c) => c - 1);
|
|
27
|
+
}
|
|
28
|
+
}, [t]);
|
|
29
|
+
const value = useMemo(() => ({ saving: count > 0, run }), [count, run]);
|
|
30
|
+
return _jsx(RecordSaveContext.Provider, { value: value, children: children });
|
|
31
|
+
}
|
|
32
|
+
const NOOP = {
|
|
33
|
+
saving: false,
|
|
34
|
+
run: async (fn) => {
|
|
35
|
+
const r = await fn();
|
|
36
|
+
return typeof r === 'string' ? r : undefined;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export function useRecordSave() {
|
|
40
|
+
return useContext(RecordSaveContext) ?? NOOP;
|
|
41
|
+
}
|