@design.estate/dees-catalog 21.43.0 → 21.44.1

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.
Files changed (73) hide show
  1. package/dist_bundle/bundle.js +535 -180
  2. package/dist_bundle/bundle.js.map +1 -1
  3. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-72W55DOJ.js → chunk-ETDITRNI.js} +4 -3
  4. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-72W55DOJ.js.map → chunk-ETDITRNI.js.map} +1 -1
  5. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PAFNUCDL.js → chunk-UD6S2QIF.js} +3 -3
  6. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-GTAAYRP5.js → chunk-WZGJITN2.js} +2 -2
  7. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-CQ56NZVB.js → de-NIKZVWN2.js} +4 -3
  8. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/de-NIKZVWN2.js.map +1 -0
  9. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-JNRW3HIY.js → dees-modal-BOGBX6EB.js} +3 -3
  10. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-Y532Z546.js → dees-workspace-terminal-M3DB4LUI.js} +4 -4
  11. package/dist_ts_web/00_commitinfo_data.js +1 -1
  12. package/dist_ts_web/elements/00group-appui/dees-appui/dees-appui.d.ts +2 -0
  13. package/dist_ts_web/elements/00group-appui/dees-appui/dees-appui.js +9 -3
  14. package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.d.ts +20 -4
  15. package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.demo.js +21 -4
  16. package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.js +65 -10
  17. package/dist_ts_web/elements/00group-dataview/dees-thread/interfaces.d.ts +5 -0
  18. package/dist_ts_web/elements/00group-dataview/dees-thread/thread.markdown.d.ts +2 -1
  19. package/dist_ts_web/elements/00group-dataview/dees-thread/thread.markdown.js +6 -3
  20. package/dist_ts_web/elements/00group-input/dees-input-reference/dees-input-reference.d.ts +1 -7
  21. package/dist_ts_web/elements/00group-input/dees-input-reference/dees-input-reference.js +22 -97
  22. package/dist_ts_web/elements/00group-input/dees-input-richtext/component.d.ts +23 -0
  23. package/dist_ts_web/elements/00group-input/dees-input-richtext/component.js +105 -5
  24. package/dist_ts_web/elements/00group-input/dees-input-richtext/demo.js +29 -1
  25. package/dist_ts_web/elements/00group-input/dees-input-richtext/index.d.ts +1 -1
  26. package/dist_ts_web/elements/00group-input/dees-input-richtext/index.js +5 -2
  27. package/dist_ts_web/elements/00group-input/dees-input-richtext/markdown.d.ts +21 -0
  28. package/dist_ts_web/elements/00group-input/dees-input-richtext/markdown.js +90 -6
  29. package/dist_ts_web/elements/00group-input/dees-input-richtext/references.d.ts +52 -0
  30. package/dist_ts_web/elements/00group-input/dees-input-richtext/references.js +152 -0
  31. package/dist_ts_web/elements/00group-input/dees-input-richtext/styles.js +23 -1
  32. package/dist_ts_web/elements/00group-input/dees-input-richtext/template.js +2 -1
  33. package/dist_ts_web/elements/00group-kanban/dees-kanban/dees-kanban.js +6 -1
  34. package/dist_ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.d.ts +15 -2
  35. package/dist_ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.js +44 -11
  36. package/dist_ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.d.ts +7 -0
  37. package/dist_ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.js +67 -5
  38. package/dist_ts_web/elements/00group-kanban/kanban.demodata.js +2 -2
  39. package/dist_ts_web/i18n/de.d.ts +6 -2
  40. package/dist_ts_web/i18n/de.js +3 -2
  41. package/dist_ts_web/i18n/messages.d.ts +6 -2
  42. package/dist_ts_web/i18n/messages.js +3 -2
  43. package/dist_ts_web/richtextmarkdown.d.ts +5 -1
  44. package/dist_ts_web/richtextmarkdown.js +6 -2
  45. package/package.json +1 -1
  46. package/readme.md +66 -10
  47. package/ts_web/00_commitinfo_data.ts +1 -1
  48. package/ts_web/elements/00group-appui/dees-appui/dees-appui.ts +10 -2
  49. package/ts_web/elements/00group-appui/dees-appui/readme.md +5 -1
  50. package/ts_web/elements/00group-dataview/dees-thread/dees-thread.demo.ts +23 -3
  51. package/ts_web/elements/00group-dataview/dees-thread/dees-thread.ts +50 -7
  52. package/ts_web/elements/00group-dataview/dees-thread/interfaces.ts +6 -0
  53. package/ts_web/elements/00group-dataview/dees-thread/thread.markdown.ts +5 -2
  54. package/ts_web/elements/00group-input/dees-input-reference/dees-input-reference.ts +20 -88
  55. package/ts_web/elements/00group-input/dees-input-richtext/component.ts +83 -3
  56. package/ts_web/elements/00group-input/dees-input-richtext/demo.ts +34 -0
  57. package/ts_web/elements/00group-input/dees-input-richtext/index.ts +6 -0
  58. package/ts_web/elements/00group-input/dees-input-richtext/markdown.ts +93 -5
  59. package/ts_web/elements/00group-input/dees-input-richtext/references.ts +171 -0
  60. package/ts_web/elements/00group-input/dees-input-richtext/styles.ts +22 -0
  61. package/ts_web/elements/00group-input/dees-input-richtext/template.ts +1 -0
  62. package/ts_web/elements/00group-kanban/dees-kanban/dees-kanban.ts +5 -0
  63. package/ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.ts +39 -10
  64. package/ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.ts +61 -3
  65. package/ts_web/elements/00group-kanban/kanban.demodata.ts +1 -1
  66. package/ts_web/i18n/de.ts +2 -1
  67. package/ts_web/i18n/messages.ts +2 -1
  68. package/ts_web/richtextmarkdown.ts +8 -0
  69. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/de-CQ56NZVB.js.map +0 -1
  70. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PAFNUCDL.js.map → chunk-UD6S2QIF.js.map} +0 -0
  71. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-GTAAYRP5.js.map → chunk-WZGJITN2.js.map} +0 -0
  72. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-JNRW3HIY.js.map → dees-modal-BOGBX6EB.js.map} +0 -0
  73. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-Y532Z546.js.map → dees-workspace-terminal-M3DB4LUI.js.map} +0 -0
@@ -3,8 +3,10 @@ import { demoFunc } from './demo.js';
3
3
  import { richtextStyles } from './styles.js';
4
4
  import { renderRichtext } from './template.js';
5
5
  import type { IToolbarButton, TRichtextFormat, TRichtextToolbarButton } from './types.js';
6
- import { docToMarkdown, markdownToDoc } from './markdown.js';
6
+ import { docToMarkdown, markdownToDoc, referenceType } from './markdown.js';
7
7
  import { markdownExtensions } from './extensions.js';
8
+ import { ReferencePicker, referenceInsertMeta, referenceNode } from './references.js';
9
+ import type { IInputReference, TReferenceSearch } from '../dees-input-reference/interfaces.js';
8
10
  import '../../00group-utility/dees-icon/dees-icon.js';
9
11
 
10
12
  import {
@@ -146,6 +148,33 @@ export class DeesInputRichtext extends DeesInputBase<string> {
146
148
  })
147
149
  accessor frameless: boolean = false;
148
150
 
151
+ /**
152
+ * Finds the records a reference links, so any app links its own: tickets, people, documents. Set,
153
+ * typing `referenceTrigger` at the start of a word opens a search at the caret, and the record
154
+ * chosen there takes the trigger's place as a reference, shown as a link with its label. In
155
+ * Markdown a reference is a link to `#reference:` and the record's id, percent-encoded
156
+ * (`[#CAT-12 Login fails](#reference:cat-12)`, `richtextReferenceHref`), in HTML
157
+ * `<span data-reference-id="cat-12">#CAT-12 Login fails</span>`. A click on a reference, or Enter on
158
+ * it, dispatches `reference-open` with its `id` and `label`. References in the value show as links
159
+ * either way.
160
+ */
161
+ @property({ attribute: false })
162
+ accessor searchReferences: TReferenceSearch | undefined = undefined;
163
+
164
+ /**
165
+ * What opens the reference search, typed at the start of a word outside code and links: `#`, so
166
+ * `C#` stays text. Escape closes the search and leaves the trigger as typed.
167
+ */
168
+ @property({ type: String, attribute: 'reference-trigger', reflect: true })
169
+ accessor referenceTrigger: string = '#';
170
+
171
+ /** The reference search's name; empty, the catalog's `richtext.referenceSearch`. */
172
+ @property({ type: String, attribute: 'reference-search-label', reflect: true })
173
+ accessor referenceSearchLabel: string = '';
174
+
175
+ @state()
176
+ accessor referenceError: string = '';
177
+
149
178
  @state()
150
179
  accessor showLinkInput: boolean = false;
151
180
 
@@ -155,6 +184,20 @@ export class DeesInputRichtext extends DeesInputBase<string> {
155
184
  private editorElement!: HTMLElement;
156
185
  private linkInputElement!: HTMLInputElement;
157
186
  private tiptapBundle: ITiptapBundle | null = null;
187
+ private readonly picker = new ReferencePicker({
188
+ element: this,
189
+ editor: () => this.editor,
190
+ search: () => this.searchReferences,
191
+ searchLabel: () => this.referenceSearchLabel || this.t('richtext.referenceSearch'),
192
+ i18n: () => this.t.i18n,
193
+ disabled: () => this.disabled,
194
+ failed: (error) => {
195
+ this.referenceError = error instanceof Error ? error.message : this.t('reference.searchFailed');
196
+ },
197
+ opened: () => {
198
+ this.referenceError = '';
199
+ },
200
+ });
158
201
 
159
202
  public editor!: Editor;
160
203
 
@@ -265,10 +308,14 @@ export class DeesInputRichtext extends DeesInputBase<string> {
265
308
 
266
309
  public updated(changed: Map<string, unknown>) {
267
310
  super.updated(changed);
268
- if (changed.has('disabled')) this.editor?.setEditable(!this.disabled, false);
311
+ if (changed.has('disabled')) {
312
+ this.editor?.setEditable(!this.disabled, false);
313
+ if (this.disabled) void this.picker.close(false);
314
+ }
269
315
  if (changed.has('placeholder') || changed.has('label')) this.nameEditable();
270
316
  if (changed.has('format') && changed.get('format') !== undefined && this.editor) {
271
317
  // Another format, another schema: the editor is built again and reads the value in the new format.
318
+ void this.picker.close(false);
272
319
  this.editor.destroy();
273
320
  this.editorElement.replaceChildren();
274
321
  this.initializeEditor();
@@ -276,6 +323,7 @@ export class DeesInputRichtext extends DeesInputBase<string> {
276
323
  return;
277
324
  }
278
325
  if (changed.has('value') && this.editor && this.value !== this.editorValue()) {
326
+ void this.picker.close(false);
279
327
  this.editor.commands.setContent(this.contentOf(this.value), false);
280
328
  this.updateWordCount();
281
329
  // The content changed after this render: the placeholder follows it.
@@ -331,14 +379,37 @@ export class DeesInputRichtext extends DeesInputBase<string> {
331
379
  ...(markdown
332
380
  ? [link, ...markdownExtensions(this.tiptapBundle, this.t('richtext.kept'))]
333
381
  : [Underline.configure({}), TextAlign.configure({ types: ['heading', 'paragraph'] }), link]),
382
+ referenceNode(this.tiptapBundle),
334
383
  Typography.configure({}),
335
384
  ],
336
385
  content: this.contentOf(this.value),
337
- onUpdate: () => {
386
+ editorProps: {
387
+ handleClickOn: (_view, _position, node, _nodePosition, event, direct) => {
388
+ if (!direct || node.type.name !== referenceType) return false;
389
+ event.preventDefault();
390
+ this.openReference({ id: String(node.attrs.id), label: String(node.attrs.label) });
391
+ return true;
392
+ },
393
+ handleDOMEvents: {
394
+ keydown: (_view, event) => {
395
+ const target = event.target as HTMLElement;
396
+ if (event.key !== 'Enter' || !target.dataset?.referenceId) return false;
397
+ event.preventDefault();
398
+ this.openReference({ id: target.dataset.referenceId, label: target.textContent ?? '' });
399
+ return true;
400
+ },
401
+ compositionend: () => {
402
+ queueMicrotask(() => this.detectReference());
403
+ return false;
404
+ },
405
+ },
406
+ },
407
+ onUpdate: ({ transaction }) => {
338
408
  this.value = this.editorValue();
339
409
  this.updateWordCount();
340
410
  this.changeSubject.next(this.value);
341
411
  this.reportValueEdit();
412
+ if (!transaction.getMeta(referenceInsertMeta)) this.detectReference();
342
413
  },
343
414
  onSelectionUpdate: () => {
344
415
  this.requestUpdate();
@@ -355,6 +426,14 @@ export class DeesInputRichtext extends DeesInputBase<string> {
355
426
  this.nameEditable();
356
427
  }
357
428
 
429
+ private detectReference(): void {
430
+ this.picker.detect(this.referenceTrigger, { wordStart: true });
431
+ }
432
+
433
+ private openReference(referenceArg: IInputReference): void {
434
+ this.dispatchEvent(new CustomEvent('reference-open', { detail: referenceArg, bubbles: true, composed: true }));
435
+ }
436
+
358
437
  private updateWordCount(): void {
359
438
  if (!this.editor) return;
360
439
  const text = this.editor.getText();
@@ -437,6 +516,7 @@ export class DeesInputRichtext extends DeesInputBase<string> {
437
516
  }
438
517
 
439
518
  public async disconnectedCallback(): Promise<void> {
519
+ void this.picker.close(false);
440
520
  await super.disconnectedCallback();
441
521
  if (this.editor) {
442
522
  this.editor.destroy();
@@ -1,6 +1,7 @@
1
1
  import { html } from '@design.estate/dees-element';
2
2
  import { focusedInputDemo } from '../../../demos/inputs.js';
3
3
  import { demoCode, demoOutput, demoSection, showDemoResult } from '../../../demos/templates.js';
4
+ import type { IInputReference } from '../dees-input-reference/interfaces.js';
4
5
  import type { TRichtextToolbarButton } from './types.js';
5
6
 
6
7
  const monthNote = [
@@ -28,6 +29,29 @@ const keptNote = [
28
29
  'Everything else is **editable** as usual.',
29
30
  ].join('\n');
30
31
 
32
+ const linkedNote = [
33
+ 'The transfer covers [#INV-2041 Hafenlogistik Bremen](#reference:inv-2041) and the second invoice.',
34
+ '',
35
+ 'Type # to link another record.',
36
+ ].join('\n');
37
+
38
+ const records: IInputReference[] = [
39
+ { id: 'inv-2041', label: '#INV-2041 Hafenlogistik Bremen' },
40
+ { id: 'inv-2042', label: '#INV-2042 Hafenlogistik Bremen' },
41
+ { id: 'ctr-17', label: '#CTR-17 Archive room lease' },
42
+ { id: 'ctr-21', label: '#CTR-21 Telekom business line' },
43
+ ];
44
+
45
+ /** The demo's records whose label holds the query, as a host's search returns them. */
46
+ const searchRecords = async (query: string): Promise<IInputReference[]> =>
47
+ records.filter((record) => record.label.toLowerCase().includes(query.toLowerCase()));
48
+
49
+ /** Shows the record a reference opens in its section's output. */
50
+ const showOpened = (event: Event) => {
51
+ const { id, label } = (event as CustomEvent<IInputReference>).detail;
52
+ showDemoResult(event.currentTarget as Element, `reference-open: ${id} (${label})`);
53
+ };
54
+
31
55
  const noteToolbar: TRichtextToolbarButton[] = ['bold', 'italic', 'bulletList', 'orderedList', 'link', 'undo', 'redo'];
32
56
 
33
57
  /** Shows the field's Markdown in its section's output. */
@@ -48,6 +72,16 @@ export const demoFunc = () => focusedInputDemo('richtext', html`
48
72
  .toolbar=\${['bold', 'italic', 'bulletList', 'orderedList', 'link', 'undo', 'redo']}
49
73
  .value=\${note.markdown}></dees-input-richtext>`)}
50
74
  `)}
75
+ ${demoSection('Linking records', 'With searchReferences the field links the host\'s records: # at the start of a word searches them at the caret, and the record chosen stands in the text as one piece, a link to #reference: and its id in the Markdown. Clicking it, or Enter on it, reports it as reference-open, for the host to open the record.', html`
76
+ <dees-input-richtext label="Payment note" format="markdown" auto-grow .minHeight=${140} .showWordCount=${false}
77
+ .toolbar=${noteToolbar} .value=${linkedNote} .searchReferences=${searchRecords} reference-search-label="Search records"
78
+ @input=${showValue} @reference-open=${showOpened}></dees-input-richtext>
79
+ ${demoOutput(linkedNote)}
80
+ ${demoCode(`<dees-input-richtext label="Payment note" format="markdown"
81
+ .searchReferences=\${(query, signal) => api.searchRecords(query, signal)}
82
+ reference-search-label="Search records"
83
+ @reference-open=\${(event) => openRecord(event.detail.id)}></dees-input-richtext>`)}
84
+ `)}
51
85
  ${demoSection('Kept as written', 'Markdown the editor does not offer — a table, an image, a footnote, a task list — is shown as written, read-only, and saved unchanged, wherever the rest of the note is edited.', html`
52
86
  <dees-input-richtext label="Close notes" format="markdown" auto-grow .minHeight=${140} .showWordCount=${false}
53
87
  .value=${keptNote} @input=${showValue}></dees-input-richtext>
@@ -6,4 +6,10 @@ export {
6
6
  // the editor writes it back, `richtextDocToMarkdown(richtextMarkdownToDoc(saved))`
7
7
  markdownToDoc as richtextMarkdownToDoc,
8
8
  docToMarkdown as richtextDocToMarkdown,
9
+ // references in the Markdown format: a reference's link, the record a link names, and Markdown as text and references
10
+ // for a host that keeps references as records
11
+ referenceHref as richtextReferenceHref,
12
+ referenceId as richtextReferenceId,
13
+ markdownToReferences as richtextMarkdownToReferences,
14
+ referencesToMarkdown as richtextReferencesToMarkdown,
9
15
  } from './markdown.js';
@@ -1,6 +1,7 @@
1
1
  import { smartmarkdown } from '../../00plugins.js';
2
2
  import type { IMarkdownHtmlOptions } from '@push.rocks/smartmarkdown';
3
3
  import type { JSONContent } from '@tiptap/core';
4
+ import type { IInputReference, TReferenceContent } from '../dees-input-reference/interfaces.js';
4
5
 
5
6
  /**
6
7
  * The richtext's Markdown format: Markdown read into the editor's document and written back from
@@ -16,6 +17,11 @@ import type { JSONContent } from '@tiptap/core';
16
17
  * What the editor does not offer — tables, images, footnotes, link references, task lists,
17
18
  * headings below level 3 — is kept as written: one atom per block (`markdownBlock`) or inline
18
19
  * construct (`markdownInline`) holding its source, written back unchanged.
20
+ *
21
+ * A reference to a record (`catalogReference`, its `id` and the `label` shown) is a link to
22
+ * `#reference:` and the id, percent-encoded: `[#CAT-12 Login fails](#reference:cat-12)`. A fragment,
23
+ * so smartmarkdown keeps it where it drops unknown schemes, and a page that does not handle it stays
24
+ * where it is.
19
25
  */
20
26
 
21
27
  /**
@@ -55,6 +61,23 @@ type TMark = NonNullable<JSONContent['marks']>[number];
55
61
  /** The node types of the editor's document in the Markdown format, beyond TipTap's StarterKit. */
56
62
  export const keptBlockType = 'markdownBlock';
57
63
  export const keptInlineType = 'markdownInline';
64
+ /** A reference to a record, in either format: its `id` and the `label` shown. */
65
+ export const referenceType = 'catalogReference';
66
+
67
+ const referencePrefix = '#reference:';
68
+
69
+ /** Where a reference to the record `idArg` links: `#reference:` and the id, percent-encoded. */
70
+ export const referenceHref = (idArg: string): string => `${referencePrefix}${encodeURIComponent(idArg)}`;
71
+
72
+ /** The record a link to `#reference:…` names; `null` for any other link. */
73
+ export const referenceId = (hrefArg: string | null | undefined): string | null => {
74
+ if (!hrefArg?.startsWith(referencePrefix)) return null;
75
+ try {
76
+ return decodeURIComponent(hrefArg.slice(referencePrefix.length)) || null;
77
+ } catch {
78
+ return null;
79
+ }
80
+ };
58
81
 
59
82
  /** Reads Markdown into the editor's document (TipTap JSON). */
60
83
  export const markdownToDoc = (sourceArg: string): JSONContent => {
@@ -68,8 +91,53 @@ export const markdownToDoc = (sourceArg: string): JSONContent => {
68
91
  /** Writes the editor's document (TipTap JSON) as Markdown. */
69
92
  export const docToMarkdown = (docArg: JSONContent): string => writeBlocks(docArg.content ?? []);
70
93
 
94
+ /**
95
+ * Markdown as text and references, for a host that keeps a text's references as records: each
96
+ * reference link (`[label](#reference:id)`, as the editor writes them) a reference, the Markdown
97
+ * between them text, as written. `referencesToMarkdown` writes it back, canonical Markdown character
98
+ * for character.
99
+ */
100
+ export const markdownToReferences = (sourceArg: string): TReferenceContent => {
101
+ const source = (sourceArg ?? '').replace(/\r\n?/g, '\n');
102
+ const tree = smartmarkdown.parseMarkdown(source, { frontmatter: richtextMarkdownRenderOptions.frontmatter });
103
+ const parts: TReferenceContent = [];
104
+ let offset = 0;
105
+ const visit = (nodesArg: IMarkdownNode[]) => {
106
+ for (const node of nodesArg) {
107
+ const reference = node.type === 'link' ? referenceOf(node) : null;
108
+ const { start, end } = node.position ?? {};
109
+ if (reference && start?.offset !== undefined && end?.offset !== undefined) {
110
+ if (start.offset > offset) parts.push({ type: 'text', text: source.slice(offset, start.offset) });
111
+ parts.push({ type: 'reference', ...reference });
112
+ offset = end.offset;
113
+ } else if (node.children) {
114
+ visit(node.children);
115
+ }
116
+ }
117
+ };
118
+ visit(tree.children as unknown as IMarkdownNode[]);
119
+ if (offset < source.length) parts.push({ type: 'text', text: source.slice(offset) });
120
+ return parts;
121
+ };
122
+
123
+ /** Text and references as Markdown: the text as written, each reference as a link to `#reference:…`. */
124
+ export const referencesToMarkdown = (contentArg: TReferenceContent): string =>
125
+ contentArg.reduce(
126
+ (markdown, part) => (part.type === 'text' ? markdown + part.text : beforeLink(markdown) + writeReference(part)),
127
+ '',
128
+ );
129
+
71
130
  // --- reading ---
72
131
 
132
+ /** A link read as a reference: to `#reference:…`, without a title, its text plain and on one line. */
133
+ const referenceOf = (nodeArg: IMarkdownNode): IInputReference | null => {
134
+ const id = referenceId(nodeArg.url);
135
+ const children = nodeArg.children ?? [];
136
+ if (id === null || nodeArg.title || !children.length || !children.every((child) => child.type === 'text')) return null;
137
+ const label = children.map((child) => child.value ?? '').join('');
138
+ return label && !label.includes('\n') ? { id, label } : null;
139
+ };
140
+
73
141
  /** Text and line breaks for text in which a newline is a line break. */
74
142
  const linesOf = (textArg: string, marksArg: TMark[]): JSONContent[] =>
75
143
  textArg.split('\n').flatMap((line, index) => [
@@ -178,11 +246,14 @@ class MarkdownReader {
178
246
  return this.inline(node.children ?? [], [...marksArg, { type: 'bold' }]);
179
247
  case 'delete':
180
248
  return this.inline(node.children ?? [], [...marksArg, { type: 'strike' }]);
181
- case 'link':
249
+ case 'link': {
250
+ const reference = referenceOf(node);
251
+ if (reference) return [withMarks({ type: referenceType, attrs: reference }, marksArg)];
182
252
  return this.inline(node.children ?? [], [
183
253
  ...marksArg,
184
254
  { type: 'link', attrs: { href: node.url ?? '', title: node.title ?? null } },
185
255
  ]);
256
+ }
186
257
  case 'inlineCode':
187
258
  return node.value ? [withMarks({ type: 'text', text: node.value }, [...marksArg, { type: 'code' }])] : [];
188
259
  case 'break':
@@ -360,6 +431,22 @@ const linkEnd = (markArg: TMark) => {
360
431
  return `](${destination}${title})`;
361
432
  };
362
433
 
434
+ /**
435
+ * What a link's `[` follows: a `!` right before it would open an image and a lone backslash would
436
+ * escape it, so either is escaped.
437
+ */
438
+ const beforeLink = (writtenArg: string): string => {
439
+ const [, backslashes, bang] = /(\\*)(!?)$/.exec(writtenArg)!;
440
+ if (bang) return backslashes.length % 2 ? writtenArg : `${writtenArg.slice(0, -1)}\\!`;
441
+ return backslashes.length % 2 ? `${writtenArg}\\` : writtenArg;
442
+ };
443
+
444
+ /** A reference as its link, its label on one line; an empty label shows the id. */
445
+ const writeReference = (referenceArg: IInputReference): string => {
446
+ const label = (referenceArg.label || referenceArg.id).replace(/[ \t]*\n[ \t]*/g, ' ');
447
+ return `[${escapeText(label, false)}${linkEnd({ type: 'link', attrs: { href: referenceHref(referenceArg.id) } })}`;
448
+ };
449
+
363
450
  /** A link whose text is its address, written as an autolink: `<https://…>`, `<name@host>`. */
364
451
  const autolink = (nodeArg: JSONContent, markArg: TMark): string | null => {
365
452
  const href = String(markArg.attrs?.href ?? '');
@@ -413,9 +500,9 @@ const escapeText = (textArg: string, lineStartArg: boolean): string => {
413
500
  return escaped.replace(/^(\d{1,9})([.)])(?=\s|$)/, '$1\\$2');
414
501
  };
415
502
 
416
- /** The marks a node has that are written as delimiters around it: all but code. */
503
+ /** The marks a node has that are written as delimiters around it: all but code, and no link around a reference, itself a link. */
417
504
  const delimitedMarks = (nodeArg: JSONContent | undefined): TMark[] =>
418
- (nodeArg?.marks ?? []).filter((mark) => mark.type in markRank);
505
+ (nodeArg?.marks ?? []).filter((mark) => mark.type in markRank && !(mark.type === 'link' && nodeArg!.type === referenceType));
419
506
 
420
507
  /**
421
508
  * One line of inline content. Marks stay open across texts that keep them; a link is outermost,
@@ -459,7 +546,7 @@ const writeLine = (nodesArg: JSONContent[], escapeLineStartArg: boolean): string
459
546
  pendingSpace += lead + trail;
460
547
  continue;
461
548
  }
462
- } else if (node.type !== keptInlineType) {
549
+ } else if (node.type !== keptInlineType && node.type !== referenceType) {
463
550
  continue;
464
551
  }
465
552
 
@@ -486,10 +573,11 @@ const writeLine = (nodesArg: JSONContent[], escapeLineStartArg: boolean): string
486
573
  continue;
487
574
  }
488
575
  for (const mark of opening) {
489
- out += mark.type === 'link' ? '[' : delimiters[mark.type];
576
+ out = mark.type === 'link' ? `${beforeLink(out)}[` : out + delimiters[mark.type];
490
577
  open.push(mark);
491
578
  }
492
579
  if (node.type === keptInlineType) out += String(node.attrs?.source ?? '');
580
+ else if (node.type === referenceType) out = beforeLink(out) + writeReference({ id: String(node.attrs?.id ?? ''), label: String(node.attrs?.label ?? '') });
493
581
  else out += code ? codeSpan(core) : escapeText(core, escapeLineStartArg && !out);
494
582
  }
495
583
  for (let closing = open.length - 1; closing >= 0; closing--) {
@@ -0,0 +1,171 @@
1
+ import type { DeesElement } from '@design.estate/dees-element';
2
+ import type { Editor } from '@tiptap/core';
3
+ import type { ITiptapBundle } from '../../../services/index.js';
4
+ import { provideOverlayI18n, type IOverlayI18nOptions } from '../../00overlay.js';
5
+ import { DeesInputDropdownPopup } from '../dees-input-dropdown/dees-input-dropdown-popup.js';
6
+ import type { IInputReference, TReferenceSearch } from '../dees-input-reference/interfaces.js';
7
+ import { referenceId, referenceType } from './markdown.js';
8
+
9
+ /**
10
+ * The editor's node for a reference to a record: an atom showing its `label`, focused and read as a
11
+ * link. In HTML it is `<span data-reference-id="…">label</span>`, in Markdown a link to
12
+ * `#reference:…` (`markdown.ts`); pasted, a reference link as a thread shows it is read as one too.
13
+ */
14
+ export const referenceNode = (bundleArg: ITiptapBundle) =>
15
+ bundleArg.Node.create({
16
+ name: referenceType,
17
+ group: 'inline',
18
+ inline: true,
19
+ atom: true,
20
+ selectable: true,
21
+ addAttributes: () => ({
22
+ id: {
23
+ default: '',
24
+ parseHTML: (element: HTMLElement) => element.getAttribute('data-reference-id') ?? referenceId(element.getAttribute('href')) ?? '',
25
+ },
26
+ label: { default: '', parseHTML: (element: HTMLElement) => element.textContent ?? '' },
27
+ }),
28
+ parseHTML: () => [
29
+ { tag: 'span[data-reference-id]' },
30
+ // before Link's `a[href]`
31
+ {
32
+ tag: 'a[href^="#reference:"]',
33
+ priority: 60,
34
+ getAttrs: (element: string | HTMLElement) =>
35
+ typeof element !== 'string' && referenceId(element.getAttribute('href')) !== null ? null : false,
36
+ },
37
+ ],
38
+ renderHTML: ({ node }) => ['span', { 'data-reference-id': String(node.attrs.id) }, String(node.attrs.label)],
39
+ renderText: ({ node }) => String(node.attrs.label),
40
+ // In the editor the reference is read-only and reached like a link; the HTML it writes stays plain.
41
+ addNodeView: () => ({ node }) => {
42
+ const dom = document.createElement('span');
43
+ dom.dataset.referenceId = String(node.attrs.id);
44
+ dom.contentEditable = 'false';
45
+ dom.setAttribute('role', 'link');
46
+ dom.tabIndex = 0;
47
+ dom.textContent = String(node.attrs.label);
48
+ return { dom };
49
+ },
50
+ });
51
+
52
+ /** The editor a reference picker serves, read when it is needed. */
53
+ export interface IReferencePickerHost {
54
+ /** The element that owns the picker: the picker's overlay owner, and where its focus returns. */
55
+ element: DeesElement;
56
+ editor: () => Editor | undefined;
57
+ search: () => TReferenceSearch | undefined;
58
+ /** The search field's name. */
59
+ searchLabel: () => string;
60
+ /** The language the picker speaks: the host's `t.i18n`. */
61
+ i18n: () => IOverlayI18nOptions['i18n'];
62
+ disabled: () => boolean;
63
+ /** The picker could not open. */
64
+ failed: (errorArg: unknown) => void;
65
+ /** The picker opened: a failure reported before no longer stands. */
66
+ opened: () => void;
67
+ }
68
+
69
+ /** The meta of the transaction that inserts a reference: the inserted text does not open the picker again. */
70
+ export const referenceInsertMeta = 'preventReferenceTrigger';
71
+
72
+ /**
73
+ * The reference picker of an editor: typing its trigger opens a search at the caret; the reference
74
+ * chosen there takes the trigger's place, followed by a space. Escape or a click elsewhere closes it
75
+ * and leaves the trigger as typed.
76
+ */
77
+ export class ReferencePicker {
78
+ private popup?: DeesInputDropdownPopup;
79
+ private opening?: Promise<void>;
80
+ private range?: { from: number; to: number };
81
+
82
+ constructor(private readonly host: IReferencePickerHost) {}
83
+
84
+ public get isOpen(): boolean {
85
+ return !!this.popup;
86
+ }
87
+
88
+ /**
89
+ * Opens the picker when the text right before the caret is the trigger. `wordStart` asks for the
90
+ * trigger to start a word, outside code and links: `#` after a letter, as in `C#`, stays text.
91
+ */
92
+ public detect(triggerArg: string, optionsArg: { wordStart?: boolean } = {}): void {
93
+ const editor = this.host.editor();
94
+ if (!editor || this.popup || this.host.disabled() || !this.host.search() || !triggerArg || editor.view.composing || !editor.isFocused) return;
95
+ const { from, to, $from } = editor.state.selection;
96
+ if (from !== to || $from.parentOffset < triggerArg.length) return;
97
+ if ($from.parent.textBetween($from.parentOffset - triggerArg.length, $from.parentOffset, '', '\ufffc') !== triggerArg) return;
98
+ if (optionsArg.wordStart) {
99
+ if ($from.parent.type.spec.code || $from.marks().some((mark) => mark.type.name === 'code' || mark.type.name === 'link')) return;
100
+ const start = $from.parentOffset - triggerArg.length;
101
+ const before = start ? $from.parent.textBetween(start - 1, start, '', '\ufffc') : '';
102
+ if (before && !/[\s\p{Ps}\p{Pi}\ufffc]/u.test(before)) return;
103
+ }
104
+ this.range = { from: from - triggerArg.length, to };
105
+ void this.open();
106
+ }
107
+
108
+ public async close(restoreFocusArg: boolean): Promise<void> {
109
+ const popup = this.popup;
110
+ const editor = this.host.editor();
111
+ const opening = this.opening;
112
+ this.popup = undefined;
113
+ this.range = undefined;
114
+ if (!popup) return;
115
+ await opening?.catch(() => undefined);
116
+ await popup.hide();
117
+ if (restoreFocusArg && this.host.element.isConnected && !this.host.disabled() && this.host.editor() === editor) editor?.commands.focus();
118
+ }
119
+
120
+ private position(): void {
121
+ const editor = this.host.editor();
122
+ if (!editor || !this.popup || !this.range) return;
123
+ const coords = editor.view.coordsAtPos(this.range.to);
124
+ // The text around the caret, which a scroll in the editor moves along
125
+ const { node } = editor.view.domAtPos(this.range.to);
126
+ this.popup.triggerElement = node instanceof HTMLElement ? node : node.parentElement;
127
+ this.popup.triggerRect = new DOMRect(coords.left, coords.top, 340, coords.bottom - coords.top);
128
+ this.popup.opensToTop = window.innerHeight - coords.bottom < 300 && coords.top > window.innerHeight - coords.bottom;
129
+ }
130
+
131
+ private async open(): Promise<void> {
132
+ const popup = (this.popup = new DeesInputDropdownPopup());
133
+ popup.ownerComponent = this.host.element;
134
+ popup.searchLabel = this.host.searchLabel();
135
+ provideOverlayI18n(popup, { i18n: this.host.i18n() });
136
+ popup.searchOptions = async (query, signal) =>
137
+ (await this.host.search()!(query, signal)).map((reference) => ({ key: reference.id, option: reference.label, payload: reference }));
138
+ this.position();
139
+ popup.addEventListener('reposition-request', () => this.position());
140
+ popup.addEventListener('close-request', () => {
141
+ void this.close(true);
142
+ });
143
+ popup.addEventListener('keydown', (event: KeyboardEvent) => {
144
+ if (event.key === 'Tab') {
145
+ event.preventDefault();
146
+ void this.close(true);
147
+ }
148
+ });
149
+ popup.addEventListener('option-selected', (event: Event) => {
150
+ const { id, label } = (event as CustomEvent<{ payload: IInputReference }>).detail.payload;
151
+ const range = this.range;
152
+ const editor = this.host.editor();
153
+ if (range && editor && !this.host.disabled()) {
154
+ editor.chain().setMeta(referenceInsertMeta, true).insertContentAt(range, [
155
+ { type: referenceType, attrs: { id, label } },
156
+ { type: 'text', text: ' ' },
157
+ ]).run();
158
+ }
159
+ void this.close(true);
160
+ });
161
+ this.opening = popup.show();
162
+ try {
163
+ await this.opening;
164
+ this.host.opened();
165
+ if (this.popup === popup && this.host.element.isConnected && !this.host.disabled()) await popup.focusSearchInput();
166
+ } catch (error) {
167
+ this.host.failed(error);
168
+ void this.close(false);
169
+ }
170
+ }
171
+ }
@@ -255,6 +255,28 @@ export const richtextStyles = [
255
255
  color: color-mix(in srgb, var(--dees-color-link) 80%, var(--dees-color-text-primary));
256
256
  }
257
257
 
258
+ /* A reference to a record: read-only, reached and opened like a link. */
259
+ .editor-content .ProseMirror [data-reference-id] {
260
+ padding: 1px 5px;
261
+ border-radius: var(--dees-radius-sm);
262
+ color: var(--dees-color-link);
263
+ background: var(--dees-color-fill-tertiary);
264
+ font-weight: 500;
265
+ cursor: pointer;
266
+ }
267
+
268
+ .editor-content .ProseMirror [data-reference-id]:focus-visible,
269
+ .editor-content .ProseMirror [data-reference-id].ProseMirror-selectednode {
270
+ outline: var(--dees-line-width-focus-ring) solid var(--dees-color-focus-ring);
271
+ outline-offset: 1px;
272
+ }
273
+
274
+ .reference-error {
275
+ margin: 4px var(--richtext-inset-inline, 0px) 0;
276
+ color: var(--dees-color-text-error);
277
+ font-size: var(--dees-font-footnote-size);
278
+ }
279
+
258
280
  /* Markdown the editor does not offer, kept as written: its source, read-only. */
259
281
  .editor-content .ProseMirror .markdown-kept {
260
282
  font-family: var(--dees-font-family-mono);
@@ -29,6 +29,7 @@ export const renderRichtext = (component: DeesInputRichtext): TemplateResult =>
29
29
  `
30
30
  : ''}
31
31
  </dees-tile>
32
+ ${component.referenceError ? html`<p class="reference-error" role="alert">${component.referenceError}</p>` : ''}
32
33
  ${component.renderDescription()}
33
34
  </div>
34
35
  `;
@@ -823,6 +823,8 @@ export class DeesKanban extends DeesElement {
823
823
  this.detail.showTicketKey = false;
824
824
  // The modal's flush body owns the surface; the detail lines up with its heading.
825
825
  this.detail.frameless = true;
826
+ // The discussion's pinned composer is opaque in that surface.
827
+ this.detail.style.setProperty('--dees-kanban-detail-surface', 'var(--dees-material-thick-bg-opaque)');
826
828
  for (const name of interactionEvents) this.detail.addEventListener(name, this.handleInteraction);
827
829
  }
828
830
  this.detail.ticket = ticket;
@@ -883,6 +885,9 @@ export class DeesKanban extends DeesElement {
883
885
  ];
884
886
  this.detail.columns = this.columns;
885
887
  this.detail.people = this.people;
888
+ this.detail.currentPerson = this.currentPersonId
889
+ ? this.people.find(person => person.id === this.currentPersonId)
890
+ : undefined;
886
891
  this.detail.provider = this.provider;
887
892
  this.detail.searchTickets = this.searchTickets;
888
893
  this.detail.projects = this.projects;