@noix-dev/brix-vue 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +74 -2
- package/package.json +117 -3
- package/src/components/address-field/AddressField.vue +337 -0
- package/src/components/address-field/index.ts +1 -0
- package/src/components/appearance-picker/AppearancePicker.vue +502 -0
- package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
- package/src/components/appearance-picker/index.ts +44 -0
- package/src/components/autofill/AutoFillDialog.vue +264 -0
- package/src/components/autofill/index.ts +1 -0
- package/src/components/badge/Badge.vue +23 -0
- package/src/components/badge/index.ts +106 -0
- package/src/components/build-stamp/BuildStamp.vue +62 -0
- package/src/components/build-stamp/index.ts +1 -0
- package/src/components/button/Button.vue +31 -0
- package/src/components/button/index.ts +122 -0
- package/src/components/card/Card.vue +29 -0
- package/src/components/card/CardAction.vue +17 -0
- package/src/components/card/CardContent.vue +14 -0
- package/src/components/card/CardDescription.vue +14 -0
- package/src/components/card/CardFooter.vue +22 -0
- package/src/components/card/CardHeader.vue +22 -0
- package/src/components/card/CardTitle.vue +29 -0
- package/src/components/card/index.ts +47 -0
- package/src/components/chart/BarChart.vue +123 -0
- package/src/components/chart/StackedBarChart.vue +149 -0
- package/src/components/chart/appearanceRevision.ts +22 -0
- package/src/components/chart/chartColor.ts +59 -0
- package/src/components/chart/index.ts +6 -0
- package/src/components/checkbox/Checkbox.vue +61 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/code-editor/CodeEditor.vue +352 -0
- package/src/components/code-editor/index.ts +9 -0
- package/src/components/code-editor/syntaxTheme.ts +110 -0
- package/src/components/colour-picker/ColourPicker.vue +421 -0
- package/src/components/colour-picker/index.ts +1 -0
- package/src/components/combobox/Combobox.vue +337 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/comments/CommentComposer.vue +302 -0
- package/src/components/comments/CommentMessage.vue +259 -0
- package/src/components/comments/CommentThread.vue +250 -0
- package/src/components/comments/commentBody.ts +185 -0
- package/src/components/comments/commentLevels.ts +139 -0
- package/src/components/comments/commentNode.ts +35 -0
- package/src/components/comments/composer.ts +20 -0
- package/src/components/comments/index.ts +29 -0
- package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/containers/Box.vue +42 -0
- package/src/components/containers/Section.vue +88 -0
- package/src/components/containers/SectionAction.vue +17 -0
- package/src/components/containers/SectionContent.vue +14 -0
- package/src/components/containers/SectionDescription.vue +14 -0
- package/src/components/containers/SectionHeader.vue +22 -0
- package/src/components/containers/SectionTitle.vue +17 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/data-table/ColumnMenu.vue +241 -0
- package/src/components/data-table/DataTable.vue +447 -0
- package/src/components/data-table/ExpandCaret.vue +34 -0
- package/src/components/data-table/SortableHead.vue +184 -0
- package/src/components/data-table/TableLoadingRow.vue +13 -0
- package/src/components/data-table/TableProgressRow.vue +26 -0
- package/src/components/data-table/columns.ts +13 -0
- package/src/components/data-table/index.ts +3 -0
- package/src/components/data-table/pinned.ts +19 -0
- package/src/components/data-table/rowActivation.ts +14 -0
- package/src/components/data-table/sort.ts +13 -0
- package/src/components/data-table/types.ts +23 -0
- package/src/components/date-picker/CalendarPanel.vue +432 -0
- package/src/components/date-picker/DateField.vue +293 -0
- package/src/components/date-picker/DatePicker.vue +147 -0
- package/src/components/date-picker/UntilDatePicker.vue +96 -0
- package/src/components/date-picker/dateFieldGuard.ts +87 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/useDateField.ts +37 -0
- package/src/components/date-range-picker/DateRangePicker.vue +247 -0
- package/src/components/date-range-picker/index.ts +1 -0
- package/src/components/date-time-picker/DateTimePicker.vue +291 -0
- package/src/components/date-time-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +250 -0
- package/src/components/dialog/DialogSurface.vue +214 -0
- package/src/components/dialog/dialogEdges.ts +65 -0
- package/src/components/dialog/dialogSizes.ts +35 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dialog/toastHost.ts +18 -0
- package/src/components/dropdown/Dropdown.vue +101 -0
- package/src/components/dropdown/DropdownItems.vue +154 -0
- package/src/components/dropdown/dropdown.ts +64 -0
- package/src/components/dropdown/index.ts +2 -0
- package/src/components/file-preview/FilePreview.vue +78 -0
- package/src/components/file-preview/index.ts +1 -0
- package/src/components/file-upload/FileUpload.vue +234 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
- package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
- package/src/components/filter-check-menu/index.ts +2 -0
- package/src/components/form-field/FormField.vue +74 -0
- package/src/components/form-field/index.ts +2 -0
- package/src/components/form-field/types.ts +5 -0
- package/src/components/frames/FrameCentred.vue +137 -0
- package/src/components/frames/FrameSidebar.vue +113 -0
- package/src/components/frames/FrameSplit.vue +109 -0
- package/src/components/frames/index.ts +3 -0
- package/src/components/icon/BellIcon.vue +27 -0
- package/src/components/icon/BoldIcon.vue +31 -0
- package/src/components/icon/CalendarDaysIcon.vue +33 -0
- package/src/components/icon/CheckIcon.vue +31 -0
- package/src/components/icon/ChevronDownIcon.vue +30 -0
- package/src/components/icon/ChevronLeftIcon.vue +31 -0
- package/src/components/icon/ChevronRightIcon.vue +31 -0
- package/src/components/icon/ChevronUpIcon.vue +30 -0
- package/src/components/icon/CircleAlertIcon.vue +29 -0
- package/src/components/icon/ClockIcon.vue +31 -0
- package/src/components/icon/Columns3Icon.vue +32 -0
- package/src/components/icon/FlipHorizontalIcon.vue +29 -0
- package/src/components/icon/ItalicIcon.vue +28 -0
- package/src/components/icon/LinkIcon.vue +27 -0
- package/src/components/icon/ListIcon.vue +29 -0
- package/src/components/icon/ListOrderedIcon.vue +28 -0
- package/src/components/icon/PenLineIcon.vue +31 -0
- package/src/components/icon/PlusIcon.vue +28 -0
- package/src/components/icon/RotateCcwIcon.vue +28 -0
- package/src/components/icon/RotateCwIcon.vue +28 -0
- package/src/components/icon/SearchIcon.vue +31 -0
- package/src/components/icon/StarIcon.vue +29 -0
- package/src/components/icon/TriangleAlertIcon.vue +29 -0
- package/src/components/icon/UnderlineIcon.vue +27 -0
- package/src/components/icon/Undo2Icon.vue +28 -0
- package/src/components/icon/XIcon.vue +31 -0
- package/src/components/icon/ZoomInIcon.vue +30 -0
- package/src/components/icon/ZoomOutIcon.vue +29 -0
- package/src/components/icon/index.ts +37 -0
- package/src/components/icon-picker/IconPicker.vue +560 -0
- package/src/components/icon-picker/index.ts +1 -0
- package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
- package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
- package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
- package/src/components/image-crop-dialog/index.ts +16 -0
- package/src/components/image-upload/ImageUpload.vue +345 -0
- package/src/components/image-upload/index.ts +2 -0
- package/src/components/input/Input.vue +48 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/keycap/Keycap.vue +49 -0
- package/src/components/keycap/index.ts +1 -0
- package/src/components/label/Label.vue +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/menu/MenuCheckboxItem.vue +63 -0
- package/src/components/menu/MenuContent.vue +45 -0
- package/src/components/menu/MenuGroup.vue +22 -0
- package/src/components/menu/MenuItem.vue +34 -0
- package/src/components/menu/MenuLabel.vue +22 -0
- package/src/components/menu/MenuRadioGroup.vue +22 -0
- package/src/components/menu/MenuRadioItem.vue +50 -0
- package/src/components/menu/MenuRoot.vue +25 -0
- package/src/components/menu/MenuSeparator.vue +27 -0
- package/src/components/menu/MenuSub.vue +29 -0
- package/src/components/menu/MenuSubContent.vue +48 -0
- package/src/components/menu/MenuSubTrigger.vue +49 -0
- package/src/components/menu/MenuTrigger.vue +22 -0
- package/src/components/menu/index.ts +20 -0
- package/src/components/menu/menuClasses.ts +74 -0
- package/src/components/morph-select/MorphSelect.vue +150 -0
- package/src/components/morph-select/index.ts +1 -0
- package/src/components/nav/NavFlyout.vue +343 -0
- package/src/components/nav/NavGroup.vue +306 -0
- package/src/components/nav/NavItem.vue +243 -0
- package/src/components/nav/NavNodes.ts +66 -0
- package/src/components/nav/NavSection.vue +105 -0
- package/src/components/nav/NavSidebar.vue +137 -0
- package/src/components/nav/index.ts +5 -0
- package/src/components/nav/navChain.ts +112 -0
- package/src/components/nav/navClasses.ts +229 -0
- package/src/components/nav/navNode.ts +10 -0
- package/src/components/nav/navRegistry.ts +24 -0
- package/src/components/notification-list/NotificationList.vue +314 -0
- package/src/components/notification-list/index.ts +2 -0
- package/src/components/notification-list/notifications.ts +21 -0
- package/src/components/pagination/Pagination.vue +296 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pin-field/PinField.vue +332 -0
- package/src/components/pin-field/index.ts +1 -0
- package/src/components/popover-panel/PopoverPanel.vue +115 -0
- package/src/components/popover-panel/index.ts +5 -0
- package/src/components/rating/Rating.vue +201 -0
- package/src/components/rating/index.ts +1 -0
- package/src/components/record-avatar/RecordAvatar.vue +76 -0
- package/src/components/record-avatar/index.ts +1 -0
- package/src/components/result-window/ResultWindow.vue +399 -0
- package/src/components/result-window/index.ts +2 -0
- package/src/components/result-window/results.ts +75 -0
- package/src/components/rich-editor/RichEditor.vue +370 -0
- package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
- package/src/components/rich-editor/index.ts +8 -0
- package/src/components/row-actions/RowActions.vue +262 -0
- package/src/components/row-actions/index.ts +2 -0
- package/src/components/row-actions/rowActions.ts +44 -0
- package/src/components/search-select/SearchSelect.vue +599 -0
- package/src/components/search-select/index.ts +2 -0
- package/src/components/search-select/types.ts +14 -0
- package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
- package/src/components/segmented-choice/index.ts +2 -0
- package/src/components/segmented-choice/segmentedOption.ts +6 -0
- package/src/components/select/Select.vue +18 -0
- package/src/components/select/SelectContent.vue +73 -0
- package/src/components/select/SelectGroup.vue +21 -0
- package/src/components/select/SelectItem.vue +47 -0
- package/src/components/select/SelectItemText.vue +12 -0
- package/src/components/select/SelectLabel.vue +17 -0
- package/src/components/select/SelectScrollDownButton.vue +36 -0
- package/src/components/select/SelectScrollUpButton.vue +36 -0
- package/src/components/select/SelectSeparator.vue +19 -0
- package/src/components/select/SelectTrigger.vue +52 -0
- package/src/components/select/SelectValue.vue +12 -0
- package/src/components/select/index.ts +11 -0
- package/src/components/session/IdleTimer.vue +71 -0
- package/src/components/session/SessionDialogs.vue +177 -0
- package/src/components/session/index.ts +2 -0
- package/src/components/split-button/SplitButton.vue +122 -0
- package/src/components/split-button/index.ts +2 -0
- package/src/components/split-button/splitButtonItem.ts +7 -0
- package/src/components/switch/Switch.vue +60 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.vue +51 -0
- package/src/components/table/TableBody.vue +14 -0
- package/src/components/table/TableCaption.vue +17 -0
- package/src/components/table/TableCell.vue +22 -0
- package/src/components/table/TableEmpty.vue +72 -0
- package/src/components/table/TableFooter.vue +17 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeader.vue +14 -0
- package/src/components/table/TableRow.vue +22 -0
- package/src/components/table/index.ts +9 -0
- package/src/components/tabs/Tabs.vue +173 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tabItem.ts +12 -0
- package/src/components/textarea/LimitedTextarea.vue +81 -0
- package/src/components/textarea/TextLimitCounter.vue +107 -0
- package/src/components/textarea/Textarea.vue +42 -0
- package/src/components/textarea/index.ts +4 -0
- package/src/components/textarea/textLimit.ts +43 -0
- package/src/components/time-picker/TimePicker.vue +522 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/toast/ToastHost.vue +276 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/update-notice/UpdateNotice.vue +103 -0
- package/src/components/update-notice/index.ts +1 -0
- package/src/components/user-menu/UserMenu.vue +154 -0
- package/src/components/user-menu/index.ts +1 -0
- package/src/index.ts +182 -0
- package/src/lib/cn.ts +21 -0
- package/src/lib/panelFocus.ts +65 -0
- package/src/lib/sessionMonitor.ts +390 -0
- package/src/lib/slotContent.ts +17 -0
- package/src/lib/updateCheck.ts +133 -0
- package/src/styles.css +82 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import Link from '@tiptap/extension-link';
|
|
4
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
5
|
+
import { Editor, EditorContent } from '@tiptap/vue-3';
|
|
6
|
+
import type { HTMLAttributes } from 'vue';
|
|
7
|
+
import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue';
|
|
8
|
+
import { cn } from '../../lib/cn';
|
|
9
|
+
import { Button } from '../button';
|
|
10
|
+
import { BoldIcon, ItalicIcon, LinkIcon, ListIcon, ListOrderedIcon, UnderlineIcon } from '../icon';
|
|
11
|
+
import RichEditorLinkDialog from './RichEditorLinkDialog.vue';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A rich text editor: six actions on a toolbar over an editable area, two-way bound to
|
|
15
|
+
* `modelValue` as HTML.
|
|
16
|
+
*
|
|
17
|
+
* **THE DOOR.** This family carries the editor library as optional peer dependencies, so it is
|
|
18
|
+
* not on the root barrel (ADR 0014): import it from `@noix-dev/brix-vue/rich-editor`, and install
|
|
19
|
+
* `@tiptap/vue-3`, `@tiptap/starter-kit` and `@tiptap/extension-link` beside it. A consumer who
|
|
20
|
+
* never renders an editor installs none of them.
|
|
21
|
+
*
|
|
22
|
+
* **THE SCHEMA IS THE KIT'S**, with its bundled link turned off in favour of the configured one
|
|
23
|
+
* below (`rel="noreferrer noopener"`, `target="_blank"`). The toolbar reaches six of what the
|
|
24
|
+
* kit brings; the rest of the schema — headings, quotes, inline code, rules — arrives by paste
|
|
25
|
+
* and by stored HTML, which is why the content styles below cover more than six.
|
|
26
|
+
*
|
|
27
|
+
* **COLOUR.** Every colour here is a role or a share of one, and the content styles are brix's
|
|
28
|
+
* own: the ported source named a typography plugin that was installed nowhere, so its lists had
|
|
29
|
+
* no markers and its headings were the size of body text. They are written as descendant
|
|
30
|
+
* variants on the editable area, the way `table/Table.vue` styles the elements it does not
|
|
31
|
+
* render itself, because the element that will carry them is created by the library.
|
|
32
|
+
*
|
|
33
|
+
* **Known limit: the editor is built on mount, so a server renders the box and the toolbar and
|
|
34
|
+
* no editable area.** That is the guard the chart and the code editor keep, here in the
|
|
35
|
+
* library's own idiom (`useEditor` builds in `onMounted` for the same reason): nothing
|
|
36
|
+
* constructs an editor where there is no DOM to own. The library would refuse to MOUNT one
|
|
37
|
+
* anyway — measured, it checks for a document itself — so the markup cannot show whether this
|
|
38
|
+
* guard holds, and the suite counts constructions instead. A server-rendered page will log
|
|
39
|
+
* a hydration mismatch when the client adds the editable area, and a consumer who minds should
|
|
40
|
+
* wrap this in a client-only boundary. Server rendering is not otherwise supported.
|
|
41
|
+
*
|
|
42
|
+
* **`update:modelValue` is the editor's own edits only.** A value arriving from outside re-seeds
|
|
43
|
+
* the document with `emitUpdate: false`, so a parent that resets the field is not told what it
|
|
44
|
+
* just wrote. `editor` is exposed for a consumer that needs a command this toolbar does not
|
|
45
|
+
* carry.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
const props = defineProps<{
|
|
49
|
+
modelValue: string;
|
|
50
|
+
/**
|
|
51
|
+
* Attributes for the editable area itself — the element the library creates, which no
|
|
52
|
+
* template here can reach. It is how a field names the control: `id`, `aria-label`,
|
|
53
|
+
* `aria-describedby`. Live: a change is applied to the running editor.
|
|
54
|
+
*
|
|
55
|
+
* `class` is **merged** into the content styles rather than replacing them, through `cn`, so
|
|
56
|
+
* a consumer can override one utility without losing the rest.
|
|
57
|
+
*/
|
|
58
|
+
contentAttributes?: Record<string, string>;
|
|
59
|
+
class?: HTMLAttributes['class'];
|
|
60
|
+
}>();
|
|
61
|
+
|
|
62
|
+
const emit = defineEmits<{ (e: 'update:modelValue', html: string): void }>();
|
|
63
|
+
|
|
64
|
+
const labels = useUiLabels();
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What the editable area draws, from roles, as descendant variants.
|
|
68
|
+
*
|
|
69
|
+
* Tailwind's reset strips the markers off a list and the size off a heading, so every one of
|
|
70
|
+
* these rules is load-bearing rather than decorative: without them a typed list has no bullets
|
|
71
|
+
* and a pasted heading reads as a paragraph, which is exactly the state the ported source
|
|
72
|
+
* shipped in. The figures are the approved design's: headings at the step above body text, both
|
|
73
|
+
* lists indented by one step with the marker in the muted ink, links in `--primary`, inline
|
|
74
|
+
* code on a `--muted` chip, a quote behind a `--border` rule.
|
|
75
|
+
*
|
|
76
|
+
* It is one string on one element because that element is the library's, handed over through
|
|
77
|
+
* `editorProps`: there is no component here to put a class on, and a `<style>` block would need
|
|
78
|
+
* `:deep()` and would lose the role utilities' own dark-mode flip.
|
|
79
|
+
*/
|
|
80
|
+
const CONTENT_CLASS = [
|
|
81
|
+
// The area itself. No outline of its own: the box below rings for the whole family.
|
|
82
|
+
'min-h-14 px-3 py-2 text-base outline-none md:text-sm',
|
|
83
|
+
// The first and last blocks sit against the padding rather than adding to it.
|
|
84
|
+
'[&>:first-child]:mt-0 [&>:last-child]:mb-0',
|
|
85
|
+
'[&_:is(h1,h2,h3,h4,h5,h6)]:font-bold',
|
|
86
|
+
'[&_h1]:mt-5 [&_h1]:mb-2 [&_h1]:text-xl',
|
|
87
|
+
'[&_h2]:mt-5 [&_h2]:mb-2 [&_h2]:text-lg',
|
|
88
|
+
'[&_h3]:mt-4 [&_h3]:mb-1 [&_h3]:text-base',
|
|
89
|
+
'[&_p]:my-3',
|
|
90
|
+
'[&_:is(ul,ol)]:my-3 [&_:is(ul,ol)]:pl-5 [&_ul]:list-disc [&_ol]:list-decimal',
|
|
91
|
+
'[&_li]:my-0.5 [&_li::marker]:text-muted-foreground',
|
|
92
|
+
'[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2',
|
|
93
|
+
'[&_code]:bg-muted [&_code]:text-foreground [&_code]:rounded-sm [&_code]:px-1.5 [&_code]:py-px [&_code]:font-mono [&_code]:text-[0.9em]',
|
|
94
|
+
'[&_blockquote]:border-border [&_blockquote]:text-muted-foreground [&_blockquote]:my-3 [&_blockquote]:border-l-2 [&_blockquote]:pl-3',
|
|
95
|
+
'[&_hr]:border-border [&_hr]:my-4 [&_hr]:border-t',
|
|
96
|
+
].join(' ');
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* One toolbar button: the ghost button's own hover and focus, with the resting ink and the
|
|
100
|
+
* active state of the approved design on top. `data-active` is the hook, so the look follows
|
|
101
|
+
* the same attribute a reader's `aria-pressed` does.
|
|
102
|
+
*/
|
|
103
|
+
const TOOL_CLASS =
|
|
104
|
+
'text-muted-foreground data-[active=true]:bg-muted data-[active=true]:text-foreground';
|
|
105
|
+
|
|
106
|
+
// Shallow on purpose: the editor is a large object that drives its own view, and a deep ref
|
|
107
|
+
// would make Vue walk it on every transaction.
|
|
108
|
+
const editor = shallowRef<Editor | undefined>();
|
|
109
|
+
|
|
110
|
+
// Bumped on every transaction so the toolbar's active state re-renders: the editor instance is
|
|
111
|
+
// not reactive, and `isActive` is a reading of its current state rather than a value.
|
|
112
|
+
const transactions = ref(0);
|
|
113
|
+
|
|
114
|
+
const linkOpen = ref(false);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* What the editable area carries: the family's content styles, and whatever the consumer needs
|
|
118
|
+
* on the control itself. Their `class` is merged in rather than over, so the two cannot be
|
|
119
|
+
* traded for one another by accident.
|
|
120
|
+
*/
|
|
121
|
+
function editableAttributes(): Record<string, string> {
|
|
122
|
+
const { class: consumerClass, ...rest } = props.contentAttributes ?? {};
|
|
123
|
+
return { ...rest, class: cn(CONTENT_CLASS, consumerClass) };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
onMounted(() => {
|
|
127
|
+
editor.value = new Editor({
|
|
128
|
+
// Read here rather than at setup, so a value that arrived in between is the one seeded.
|
|
129
|
+
content: props.modelValue,
|
|
130
|
+
extensions: [
|
|
131
|
+
// The kit bundles a link of its own; this one carries the attributes below.
|
|
132
|
+
StarterKit.configure({ link: false }),
|
|
133
|
+
Link.configure({
|
|
134
|
+
// The editor is for writing, so a click inside it places the caret rather than
|
|
135
|
+
// leaving the page.
|
|
136
|
+
openOnClick: false,
|
|
137
|
+
HTMLAttributes: { rel: 'noreferrer noopener', target: '_blank' },
|
|
138
|
+
}),
|
|
139
|
+
],
|
|
140
|
+
editorProps: { attributes: editableAttributes() },
|
|
141
|
+
onUpdate: ({ editor: changed }) => emit('update:modelValue', changed.getHTML()),
|
|
142
|
+
onTransaction: () => {
|
|
143
|
+
transactions.value += 1;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const active = computed(() => {
|
|
149
|
+
// Read so the computed is invalidated by a transaction, and by the editor arriving.
|
|
150
|
+
void transactions.value;
|
|
151
|
+
const current = editor.value;
|
|
152
|
+
return {
|
|
153
|
+
bold: current?.isActive('bold') ?? false,
|
|
154
|
+
italic: current?.isActive('italic') ?? false,
|
|
155
|
+
underline: current?.isActive('underline') ?? false,
|
|
156
|
+
bulletList: current?.isActive('bulletList') ?? false,
|
|
157
|
+
orderedList: current?.isActive('orderedList') ?? false,
|
|
158
|
+
link: current?.isActive('link') ?? false,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* A value from outside — a document loaded, a parent resetting the field after posting —
|
|
164
|
+
* re-seeds the document. `emitUpdate: false`, because the parent already knows what it wrote.
|
|
165
|
+
* `CodeEditor` chose the opposite: its re-seed is a document change like any other and is echoed
|
|
166
|
+
* back out through its update listener. Each is a decision, not an oversight.
|
|
167
|
+
*
|
|
168
|
+
* **The comparison is the whole of the loop guard, and it has three outcomes rather than two.**
|
|
169
|
+
* `update:modelValue` fires on every keystroke, and a `v-model` writes back what it heard:
|
|
170
|
+
*
|
|
171
|
+
* - an **identical** echo stops here, and this comparison is the whole of what stops it. It is
|
|
172
|
+
* the ordinary case — every keystroke under a plain `v-model` — and it is not harmless to let
|
|
173
|
+
* through: `setContent` replaces the document even when the new content equals the old, and
|
|
174
|
+
* ProseMirror then maps the selection to the END of the replacement, so the caret jumps out of
|
|
175
|
+
* the middle of a word (measured, and `RichEditor.test.ts` holds it). No flag of the kind the
|
|
176
|
+
* code editor keeps is needed for it: there the value is plain text and the comparison has the
|
|
177
|
+
* same shape, here the HTML the editor produced is the HTML it is handed back;
|
|
178
|
+
* - a **changed** echo — a parent that trims, sanitises or normalises — wins, deliberately. It
|
|
179
|
+
* re-seeds the document and moves the caret, which is visible and is the honest outcome: the
|
|
180
|
+
* alternative is an editor and a model that disagree about what was written. `CodeEditor`
|
|
181
|
+
* takes that alternative on purpose and suppresses a changed write-back for the length of a
|
|
182
|
+
* keystroke, so the caret stays where it was; the two files weigh the same trade differently;
|
|
183
|
+
* - a **late** echo loses an edit, and nothing here can tell: a parent that debounces, or round
|
|
184
|
+
* trips through a store, can write value N back after the editor has reached N+1, and the
|
|
185
|
+
* re-seed then discards the newer keystroke. A flag would not catch it either — by then the
|
|
186
|
+
* emit it would have guarded is long over. A consumer whose write-back is asynchronous should
|
|
187
|
+
* hold the value in the parent and write it back synchronously, or not at all.
|
|
188
|
+
*/
|
|
189
|
+
watch(
|
|
190
|
+
() => props.modelValue,
|
|
191
|
+
(value) => {
|
|
192
|
+
const current = editor.value;
|
|
193
|
+
if (!current || value === current.getHTML()) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
current.commands.setContent(value, { emitUpdate: false });
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Live, so a field that renames its control mid-life is obeyed. The getter is the serialised
|
|
201
|
+
// attributes rather than the object: a parent that rebuilds the literal on every render — which
|
|
202
|
+
// is what `FormField`'s slot does on every keystroke — would otherwise reconfigure the running
|
|
203
|
+
// editor on each one.
|
|
204
|
+
watch(
|
|
205
|
+
() => JSON.stringify(props.contentAttributes ?? {}),
|
|
206
|
+
() => editor.value?.setOptions({ editorProps: { attributes: editableAttributes() } }),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
onBeforeUnmount(() => {
|
|
210
|
+
editor.value?.destroy();
|
|
211
|
+
editor.value = undefined;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
function toggleBold(): void {
|
|
215
|
+
editor.value?.chain().focus().toggleBold().run();
|
|
216
|
+
}
|
|
217
|
+
function toggleItalic(): void {
|
|
218
|
+
editor.value?.chain().focus().toggleItalic().run();
|
|
219
|
+
}
|
|
220
|
+
function toggleUnderline(): void {
|
|
221
|
+
editor.value?.chain().focus().toggleUnderline().run();
|
|
222
|
+
}
|
|
223
|
+
function toggleBulletList(): void {
|
|
224
|
+
editor.value?.chain().focus().toggleBulletList().run();
|
|
225
|
+
}
|
|
226
|
+
function toggleOrderedList(): void {
|
|
227
|
+
editor.value?.chain().focus().toggleOrderedList().run();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The link flow, and the one thing about it that is not obvious: the chain runs when the dialog
|
|
232
|
+
* RETURNS, never before it opens. The selection is the editor's own state and survives the
|
|
233
|
+
* focus moving into the dialog, so the words the reader chose are still chosen while they type
|
|
234
|
+
* the URL — and a cancel leaves the document and the selection exactly as they were. A command
|
|
235
|
+
* run on the way out instead would have to put the selection back.
|
|
236
|
+
*/
|
|
237
|
+
function setLink(url: string): void {
|
|
238
|
+
editor.value?.chain().focus().setLink({ href: url }).run();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The dialog has no trigger of its own for reka to hand the focus back to, so without this it
|
|
243
|
+
* would fall to the page. It goes back into the editor, caret and all, which is where the reader
|
|
244
|
+
* was — and `Dialog`'s own event is the place to do it, before reka moves anything.
|
|
245
|
+
*/
|
|
246
|
+
function returnFocus(event: Event): void {
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
editor.value?.commands.focus();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
defineExpose({ editor });
|
|
252
|
+
</script>
|
|
253
|
+
|
|
254
|
+
<template>
|
|
255
|
+
<div
|
|
256
|
+
data-slot="rich-editor"
|
|
257
|
+
:class="
|
|
258
|
+
cn(
|
|
259
|
+
// The box, and the focus recipe for the whole family: what takes focus is the
|
|
260
|
+
// library's own editable area inside it, so the ring is drawn on `focus-within`.
|
|
261
|
+
// The resting edge is `--muted-foreground`, which is CLAUDE.md's rule for an
|
|
262
|
+
// active text field, rather than the approved mockup's `--input`: that edge is a
|
|
263
|
+
// contrast ratio of at most 1.82 over the ground it is drawn on, under the 3:1
|
|
264
|
+
// an indicator needs, where this one is at least 4.73. `docs/design/README.md`
|
|
265
|
+
// records the deviation and carries every figure, in one place.
|
|
266
|
+
'border-muted-foreground focus-within:border-ring focus-within:ring-ring focus-within:ring-offset-background bg-background overflow-hidden rounded-lg border outline-none focus-within:ring-2 focus-within:ring-offset-2',
|
|
267
|
+
props.class,
|
|
268
|
+
)
|
|
269
|
+
"
|
|
270
|
+
>
|
|
271
|
+
<!-- The hairline and the separators stay on `--input`, as the mockup draws them: they
|
|
272
|
+
divide two areas inside one box, which is decoration, while the box's own edge is an
|
|
273
|
+
indicator and is held to 3:1. -->
|
|
274
|
+
<div
|
|
275
|
+
role="group"
|
|
276
|
+
:aria-label="labels.editorToolbar"
|
|
277
|
+
data-testid="rich-editor-toolbar"
|
|
278
|
+
class="border-input bg-muted/50 flex items-center gap-0.5 border-b px-1.5 py-1"
|
|
279
|
+
>
|
|
280
|
+
<Button
|
|
281
|
+
type="button"
|
|
282
|
+
variant="ghost"
|
|
283
|
+
size="icon-sm"
|
|
284
|
+
:class="TOOL_CLASS"
|
|
285
|
+
data-testid="rich-editor-bold"
|
|
286
|
+
:data-active="active.bold"
|
|
287
|
+
:aria-pressed="active.bold"
|
|
288
|
+
:aria-label="labels.editorBold"
|
|
289
|
+
@click="toggleBold"
|
|
290
|
+
>
|
|
291
|
+
<slot name="bold-icon"><BoldIcon /></slot>
|
|
292
|
+
</Button>
|
|
293
|
+
<Button
|
|
294
|
+
type="button"
|
|
295
|
+
variant="ghost"
|
|
296
|
+
size="icon-sm"
|
|
297
|
+
:class="TOOL_CLASS"
|
|
298
|
+
data-testid="rich-editor-italic"
|
|
299
|
+
:data-active="active.italic"
|
|
300
|
+
:aria-pressed="active.italic"
|
|
301
|
+
:aria-label="labels.editorItalic"
|
|
302
|
+
@click="toggleItalic"
|
|
303
|
+
>
|
|
304
|
+
<slot name="italic-icon"><ItalicIcon /></slot>
|
|
305
|
+
</Button>
|
|
306
|
+
<Button
|
|
307
|
+
type="button"
|
|
308
|
+
variant="ghost"
|
|
309
|
+
size="icon-sm"
|
|
310
|
+
:class="TOOL_CLASS"
|
|
311
|
+
data-testid="rich-editor-underline"
|
|
312
|
+
:data-active="active.underline"
|
|
313
|
+
:aria-pressed="active.underline"
|
|
314
|
+
:aria-label="labels.editorUnderline"
|
|
315
|
+
@click="toggleUnderline"
|
|
316
|
+
>
|
|
317
|
+
<slot name="underline-icon"><UnderlineIcon /></slot>
|
|
318
|
+
</Button>
|
|
319
|
+
<span aria-hidden="true" class="bg-input mx-1 h-4 w-px" />
|
|
320
|
+
<Button
|
|
321
|
+
type="button"
|
|
322
|
+
variant="ghost"
|
|
323
|
+
size="icon-sm"
|
|
324
|
+
:class="TOOL_CLASS"
|
|
325
|
+
data-testid="rich-editor-bullet-list"
|
|
326
|
+
:data-active="active.bulletList"
|
|
327
|
+
:aria-pressed="active.bulletList"
|
|
328
|
+
:aria-label="labels.editorBulletList"
|
|
329
|
+
@click="toggleBulletList"
|
|
330
|
+
>
|
|
331
|
+
<slot name="bullet-list-icon"><ListIcon /></slot>
|
|
332
|
+
</Button>
|
|
333
|
+
<Button
|
|
334
|
+
type="button"
|
|
335
|
+
variant="ghost"
|
|
336
|
+
size="icon-sm"
|
|
337
|
+
:class="TOOL_CLASS"
|
|
338
|
+
data-testid="rich-editor-ordered-list"
|
|
339
|
+
:data-active="active.orderedList"
|
|
340
|
+
:aria-pressed="active.orderedList"
|
|
341
|
+
:aria-label="labels.editorOrderedList"
|
|
342
|
+
@click="toggleOrderedList"
|
|
343
|
+
>
|
|
344
|
+
<slot name="ordered-list-icon"><ListOrderedIcon /></slot>
|
|
345
|
+
</Button>
|
|
346
|
+
<span aria-hidden="true" class="bg-input mx-1 h-4 w-px" />
|
|
347
|
+
<!-- The sixth opens a dialog rather than toggling a mark, so it says so and carries
|
|
348
|
+
no pressed state; `data-active` here means the caret is inside a link. -->
|
|
349
|
+
<Button
|
|
350
|
+
type="button"
|
|
351
|
+
variant="ghost"
|
|
352
|
+
size="icon-sm"
|
|
353
|
+
:class="TOOL_CLASS"
|
|
354
|
+
data-testid="rich-editor-link"
|
|
355
|
+
aria-haspopup="dialog"
|
|
356
|
+
:data-active="active.link"
|
|
357
|
+
:aria-label="labels.editorLink"
|
|
358
|
+
@click="linkOpen = true"
|
|
359
|
+
>
|
|
360
|
+
<slot name="link-icon"><LinkIcon /></slot>
|
|
361
|
+
</Button>
|
|
362
|
+
</div>
|
|
363
|
+
<EditorContent data-testid="rich-editor-content" :editor="editor" />
|
|
364
|
+
<RichEditorLinkDialog
|
|
365
|
+
v-model:open="linkOpen"
|
|
366
|
+
@confirm="setLink"
|
|
367
|
+
@close-auto-focus="returnFocus"
|
|
368
|
+
/>
|
|
369
|
+
</div>
|
|
370
|
+
</template>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import { ref, watch } from 'vue';
|
|
4
|
+
import { Button } from '../button';
|
|
5
|
+
import { Dialog } from '../dialog';
|
|
6
|
+
import { FormField } from '../form-field';
|
|
7
|
+
import { Input } from '../input';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Where the rich editor asks for a link's target. It is the shipped `Dialog`, `FormField` and
|
|
11
|
+
* `Input` and nothing else — the panel, the label, the field edge and both buttons are already
|
|
12
|
+
* roles one layer down, so the one colour utility it draws is the hint's `text-muted-foreground`,
|
|
13
|
+
* which the approved mockup sets muted and at the extra-small size.
|
|
14
|
+
*
|
|
15
|
+
* **It replaces `window.prompt`**, which the ported source used. A native prompt cannot be
|
|
16
|
+
* themed, cannot be reached by a test without a stub, and blocks the page — and it answered
|
|
17
|
+
* `null` both for a cancel and for an empty field, so one branch stood for two gestures. Here
|
|
18
|
+
* they are two: a cancel closes and hands nothing back, an empty confirmation **stays open**
|
|
19
|
+
* with the caret still in the field, because closing it would lose the words the reader
|
|
20
|
+
* selected and send them back to the toolbar.
|
|
21
|
+
*
|
|
22
|
+
* It does not own the editor and never touches it. It hands a URL out on `confirm` and leaves
|
|
23
|
+
* the selection, the link command and the focus to `RichEditor`, which is the one holding the
|
|
24
|
+
* editor — a dialog that ran the command itself would need the editor as a prop and would be
|
|
25
|
+
* untestable without one.
|
|
26
|
+
*
|
|
27
|
+
* `hide-close` for the reason `ConfirmDialog` has it: the dialog is answered with its own two
|
|
28
|
+
* buttons. That also settles where the focus lands — with no cross in front of it, the field is
|
|
29
|
+
* the panel's first focusable element and reka puts the focus there itself, which is what a
|
|
30
|
+
* dialog holding one field wants. Escape and a press outside still close it, which is a cancel.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const props = defineProps<{ open: boolean }>();
|
|
34
|
+
|
|
35
|
+
const emit = defineEmits<{
|
|
36
|
+
(e: 'update:open', value: boolean): void;
|
|
37
|
+
/** The trimmed URL. Never the empty string: an empty field does not confirm. */
|
|
38
|
+
(e: 'confirm', url: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* `Dialog`'s own, forwarded: this dialog has no trigger for reka to hand the focus back to,
|
|
41
|
+
* and the editor is where the reader was. The one holding the editor is the one that can
|
|
42
|
+
* focus it, so the event goes up rather than the editor coming down as a prop.
|
|
43
|
+
*/
|
|
44
|
+
(e: 'closeAutoFocus', event: Event): void;
|
|
45
|
+
}>();
|
|
46
|
+
|
|
47
|
+
const labels = useUiLabels();
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The scheme the field opens with, as the approved design draws it. It is a starting point and
|
|
51
|
+
* not a value the dialog insists on: a reader who clears the field cannot confirm, and one who
|
|
52
|
+
* pastes a whole URL over it replaces it.
|
|
53
|
+
*/
|
|
54
|
+
const SCHEME = 'https://';
|
|
55
|
+
|
|
56
|
+
const url = ref(SCHEME);
|
|
57
|
+
|
|
58
|
+
// Every opening starts from the scheme, so a URL that was typed and dropped does not come back
|
|
59
|
+
// the next time the dialog is asked for.
|
|
60
|
+
watch(
|
|
61
|
+
() => props.open,
|
|
62
|
+
(open) => {
|
|
63
|
+
if (open) {
|
|
64
|
+
url.value = SCHEME;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
function confirm(): void {
|
|
70
|
+
const target = url.value.trim();
|
|
71
|
+
if (target === '') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
emit('confirm', target);
|
|
75
|
+
emit('update:open', false);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onEnter(event: KeyboardEvent): void {
|
|
79
|
+
// Enter that confirms an input-method choice is not a request to add the link.
|
|
80
|
+
if (!event.isComposing) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
confirm();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<Dialog
|
|
89
|
+
:open="props.open"
|
|
90
|
+
:title="labels.editorLinkTitle"
|
|
91
|
+
:description="labels.editorLinkHint"
|
|
92
|
+
size="sm"
|
|
93
|
+
hide-close
|
|
94
|
+
@update:open="(value: boolean) => emit('update:open', value)"
|
|
95
|
+
@close-auto-focus="(event: Event) => emit('closeAutoFocus', event)"
|
|
96
|
+
>
|
|
97
|
+
<div class="grid gap-3">
|
|
98
|
+
<!-- Visible here and, through `description` above, announced with the dialog's name:
|
|
99
|
+
the focus goes straight to the field, so a reader who never reads the body would
|
|
100
|
+
otherwise not be told what the link attaches to. A screen reader that walks the
|
|
101
|
+
body therefore hears it twice. `Dialog` renders its description as a separate
|
|
102
|
+
screen-reader-only element; pointing it at this one would mean a consumer
|
|
103
|
+
`aria-describedby`, which makes reka log its "Missing Description" warning, so
|
|
104
|
+
the duplicate is accepted until `Dialog` changes. -->
|
|
105
|
+
<p class="text-muted-foreground text-xs">{{ labels.editorLinkHint }}</p>
|
|
106
|
+
<FormField :label="labels.editorLinkField">
|
|
107
|
+
<template #default="{ id, describedBy }">
|
|
108
|
+
<Input
|
|
109
|
+
:id="id"
|
|
110
|
+
v-model="url"
|
|
111
|
+
type="url"
|
|
112
|
+
spellcheck="false"
|
|
113
|
+
:aria-describedby="describedBy"
|
|
114
|
+
@keydown.enter="onEnter"
|
|
115
|
+
/>
|
|
116
|
+
</template>
|
|
117
|
+
</FormField>
|
|
118
|
+
</div>
|
|
119
|
+
<template #footer>
|
|
120
|
+
<Button
|
|
121
|
+
type="button"
|
|
122
|
+
variant="outline"
|
|
123
|
+
data-testid="rich-editor-link-cancel"
|
|
124
|
+
@click="emit('update:open', false)"
|
|
125
|
+
>
|
|
126
|
+
{{ labels.editorLinkCancel }}
|
|
127
|
+
</Button>
|
|
128
|
+
<Button type="button" data-testid="rich-editor-link-confirm" @click="confirm">
|
|
129
|
+
{{ labels.editorLinkConfirm }}
|
|
130
|
+
</Button>
|
|
131
|
+
</template>
|
|
132
|
+
</Dialog>
|
|
133
|
+
</template>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The rich editor's door (ADR 0014). The family carries `@tiptap/vue-3`,
|
|
2
|
+
// `@tiptap/starter-kit` and `@tiptap/extension-link` as optional peers, so it stays off the
|
|
3
|
+
// root barrel: a consumer who imports a button must not install an editor.
|
|
4
|
+
//
|
|
5
|
+
// Only the editor leaves. `RichEditorLinkDialog` is how this family asks for a URL and is of no
|
|
6
|
+
// use without it — exporting it would publish a surface nobody asked for, and one that reaches
|
|
7
|
+
// the library through nothing but its sibling.
|
|
8
|
+
export { default as RichEditor } from './RichEditor.vue';
|