@design.estate/dees-catalog 21.42.0 → 21.44.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/dist_bundle/bundle.js +541 -182
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-72W55DOJ.js → chunk-ETDITRNI.js} +4 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-72W55DOJ.js.map → chunk-ETDITRNI.js.map} +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PAFNUCDL.js → chunk-UD6S2QIF.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-GTAAYRP5.js → chunk-WZGJITN2.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-CQ56NZVB.js → de-NIKZVWN2.js} +4 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/de-NIKZVWN2.js.map +1 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-JNRW3HIY.js → dees-modal-BOGBX6EB.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-Y532Z546.js → dees-workspace-terminal-M3DB4LUI.js} +4 -4
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.d.ts +20 -4
- package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.demo.js +21 -4
- package/dist_ts_web/elements/00group-dataview/dees-thread/dees-thread.js +65 -10
- package/dist_ts_web/elements/00group-dataview/dees-thread/interfaces.d.ts +5 -0
- package/dist_ts_web/elements/00group-dataview/dees-thread/thread.markdown.d.ts +2 -1
- package/dist_ts_web/elements/00group-dataview/dees-thread/thread.markdown.js +6 -3
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.d.ts +2 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.js +2 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-composer/dees-harness-composer.d.ts +10 -2
- package/dist_ts_web/elements/00group-harness/dees-harness-composer/dees-harness-composer.js +26 -6
- package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.d.ts +2 -0
- package/dist_ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.js +3 -2
- package/dist_ts_web/elements/00group-input/dees-input-reference/dees-input-reference.d.ts +1 -7
- package/dist_ts_web/elements/00group-input/dees-input-reference/dees-input-reference.js +22 -97
- package/dist_ts_web/elements/00group-input/dees-input-richtext/component.d.ts +23 -0
- package/dist_ts_web/elements/00group-input/dees-input-richtext/component.js +105 -5
- package/dist_ts_web/elements/00group-input/dees-input-richtext/demo.js +29 -1
- package/dist_ts_web/elements/00group-input/dees-input-richtext/index.d.ts +1 -1
- package/dist_ts_web/elements/00group-input/dees-input-richtext/index.js +5 -2
- package/dist_ts_web/elements/00group-input/dees-input-richtext/markdown.d.ts +21 -0
- package/dist_ts_web/elements/00group-input/dees-input-richtext/markdown.js +90 -6
- package/dist_ts_web/elements/00group-input/dees-input-richtext/references.d.ts +52 -0
- package/dist_ts_web/elements/00group-input/dees-input-richtext/references.js +152 -0
- package/dist_ts_web/elements/00group-input/dees-input-richtext/styles.js +23 -1
- package/dist_ts_web/elements/00group-input/dees-input-richtext/template.js +2 -1
- package/dist_ts_web/elements/00group-kanban/dees-kanban/dees-kanban.js +6 -1
- package/dist_ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.d.ts +15 -2
- package/dist_ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.js +44 -11
- package/dist_ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.d.ts +7 -0
- package/dist_ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.js +67 -5
- package/dist_ts_web/elements/00group-kanban/kanban.demodata.js +2 -2
- package/dist_ts_web/i18n/de.d.ts +6 -2
- package/dist_ts_web/i18n/de.js +3 -2
- package/dist_ts_web/i18n/messages.d.ts +6 -2
- package/dist_ts_web/i18n/messages.js +3 -2
- package/dist_ts_web/richtextmarkdown.d.ts +5 -1
- package/dist_ts_web/richtextmarkdown.js +6 -2
- package/package.json +1 -1
- package/readme.md +68 -12
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-dataview/dees-thread/dees-thread.demo.ts +23 -3
- package/ts_web/elements/00group-dataview/dees-thread/dees-thread.ts +50 -7
- package/ts_web/elements/00group-dataview/dees-thread/interfaces.ts +6 -0
- package/ts_web/elements/00group-dataview/dees-thread/thread.markdown.ts +5 -2
- package/ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.ts +2 -1
- package/ts_web/elements/00group-harness/dees-harness-composer/dees-harness-composer.ts +28 -5
- package/ts_web/elements/00group-input/dees-input-multitoggle/dees-input-multitoggle.ts +4 -2
- package/ts_web/elements/00group-input/dees-input-reference/dees-input-reference.ts +20 -88
- package/ts_web/elements/00group-input/dees-input-richtext/component.ts +83 -3
- package/ts_web/elements/00group-input/dees-input-richtext/demo.ts +34 -0
- package/ts_web/elements/00group-input/dees-input-richtext/index.ts +6 -0
- package/ts_web/elements/00group-input/dees-input-richtext/markdown.ts +93 -5
- package/ts_web/elements/00group-input/dees-input-richtext/references.ts +171 -0
- package/ts_web/elements/00group-input/dees-input-richtext/styles.ts +22 -0
- package/ts_web/elements/00group-input/dees-input-richtext/template.ts +1 -0
- package/ts_web/elements/00group-kanban/dees-kanban/dees-kanban.ts +5 -0
- package/ts_web/elements/00group-kanban/dees-kanban-discussion/dees-kanban-discussion.ts +39 -10
- package/ts_web/elements/00group-kanban/dees-kanban-ticket-detail/dees-kanban-ticket-detail.ts +61 -3
- package/ts_web/elements/00group-kanban/kanban.demodata.ts +1 -1
- package/ts_web/i18n/de.ts +2 -1
- package/ts_web/i18n/messages.ts +2 -1
- package/ts_web/richtextmarkdown.ts +8 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/de-CQ56NZVB.js.map +0 -1
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PAFNUCDL.js.map → chunk-UD6S2QIF.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-GTAAYRP5.js.map → chunk-WZGJITN2.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-JNRW3HIY.js.map → dees-modal-BOGBX6EB.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-Y532Z546.js.map → dees-workspace-terminal-M3DB4LUI.js.map} +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { provideOverlayI18n } from '../../00overlay.js';
|
|
2
1
|
import { DeesElement, customElement, property, state, html, css, cssManager } from '@design.estate/dees-element';
|
|
3
2
|
import type { Editor } from '@tiptap/core';
|
|
4
3
|
import { DeesServiceLibLoader } from '../../../services/DeesServiceLibLoader.js';
|
|
5
4
|
import { themeDefaultStyles } from '../../00theme.js';
|
|
6
|
-
import {
|
|
5
|
+
import { ReferencePicker, referenceInsertMeta, referenceNode } from '../dees-input-richtext/references.js';
|
|
7
6
|
import type { IInputReference, TReferenceContent, TReferenceSearch } from './interfaces.js';
|
|
8
7
|
import { referenceContent, referenceDocument } from './document.js';
|
|
9
8
|
import { demoFunc } from './dees-input-reference.demo.js';
|
|
@@ -33,9 +32,16 @@ export class DeesInputReference extends DeesElement {
|
|
|
33
32
|
private editor?: Editor;
|
|
34
33
|
private initializing?: Promise<void>;
|
|
35
34
|
private connection = 0;
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
private readonly picker = new ReferencePicker({
|
|
36
|
+
element: this,
|
|
37
|
+
editor: () => this.editor,
|
|
38
|
+
search: () => this.searchReferences,
|
|
39
|
+
searchLabel: () => this.searchLabel || this.t('reference.search'),
|
|
40
|
+
i18n: () => this.t.i18n,
|
|
41
|
+
disabled: () => this.disabled,
|
|
42
|
+
failed: (error) => { this.loadError = error instanceof Error ? error.message : this.t('reference.searchFailed'); },
|
|
43
|
+
opened: () => { this.loadError = ''; },
|
|
44
|
+
});
|
|
39
45
|
private serializedValue = '';
|
|
40
46
|
|
|
41
47
|
public static styles = [themeDefaultStyles, cssManager.defaultStyles, css`
|
|
@@ -75,23 +81,14 @@ export class DeesInputReference extends DeesElement {
|
|
|
75
81
|
const connection = this.connection;
|
|
76
82
|
const operation = (async () => {
|
|
77
83
|
await this.updateComplete;
|
|
78
|
-
const
|
|
84
|
+
const bundle = await DeesServiceLibLoader.getInstance().loadTiptap();
|
|
85
|
+
const { Editor, StarterKit } = bundle;
|
|
79
86
|
if (!this.isConnected || connection !== this.connection) return;
|
|
80
|
-
const referenceNode = Node.create({
|
|
81
|
-
name: 'catalogReference', group: 'inline', inline: true, atom: true, selectable: true,
|
|
82
|
-
addAttributes: () => ({
|
|
83
|
-
id: { default: '', parseHTML: element => element.getAttribute('data-reference-id') },
|
|
84
|
-
label: { default: '', parseHTML: element => element.textContent },
|
|
85
|
-
}),
|
|
86
|
-
parseHTML: () => [{ tag: 'span[data-reference-id]' }],
|
|
87
|
-
renderHTML: ({ node }) => ['span', { 'data-reference-id': String(node.attrs.id), contenteditable: 'false', role: 'link', tabindex: '0' }, String(node.attrs.label)],
|
|
88
|
-
renderText: ({ node }) => String(node.attrs.label),
|
|
89
|
-
});
|
|
90
87
|
this.editor = new Editor({
|
|
91
88
|
element: this.shadowRoot!.querySelector<HTMLElement>('.editor')!,
|
|
92
89
|
injectCSS: false,
|
|
93
90
|
editable: !this.disabled,
|
|
94
|
-
extensions: [StarterKit.configure({ blockquote: false, bold: false, bulletList: false, code: false, codeBlock: false, heading: false, horizontalRule: false, italic: false, listItem: false, orderedList: false, strike: false }), referenceNode],
|
|
91
|
+
extensions: [StarterKit.configure({ blockquote: false, bold: false, bulletList: false, code: false, codeBlock: false, heading: false, horizontalRule: false, italic: false, listItem: false, orderedList: false, strike: false }), referenceNode(bundle)],
|
|
95
92
|
content: referenceDocument(this.value),
|
|
96
93
|
editorProps: {
|
|
97
94
|
attributes: { role: 'textbox', 'aria-multiline': 'true', 'aria-label': this.label || this.t('reference.label'), 'data-placeholder': this.placeholder || this.t('reference.placeholder') },
|
|
@@ -110,14 +107,14 @@ export class DeesInputReference extends DeesElement {
|
|
|
110
107
|
}
|
|
111
108
|
return false;
|
|
112
109
|
},
|
|
113
|
-
compositionend: () => { queueMicrotask(() => this.
|
|
110
|
+
compositionend: () => { queueMicrotask(() => this.picker.detect(this.trigger)); return false; },
|
|
114
111
|
},
|
|
115
112
|
},
|
|
116
113
|
onUpdate: ({ editor, transaction }) => {
|
|
117
114
|
this.value = referenceContent(editor.getJSON());
|
|
118
115
|
this.serializedValue = JSON.stringify(this.value);
|
|
119
116
|
this.dispatchEvent(new CustomEvent('reference-input', { detail: { value: this.value }, bubbles: true, composed: true }));
|
|
120
|
-
if (!transaction.getMeta(
|
|
117
|
+
if (!transaction.getMeta(referenceInsertMeta)) this.picker.detect(this.trigger);
|
|
121
118
|
},
|
|
122
119
|
});
|
|
123
120
|
this.serializedValue = JSON.stringify(this.value);
|
|
@@ -131,16 +128,16 @@ export class DeesInputReference extends DeesElement {
|
|
|
131
128
|
public updated(changed: Map<string, unknown>): void {
|
|
132
129
|
if (changed.has('documentKey') && changed.get('documentKey') !== undefined && this.editor) {
|
|
133
130
|
this.connection++;
|
|
134
|
-
void this.
|
|
131
|
+
void this.picker.close(false);
|
|
135
132
|
this.editor.destroy(); this.editor = undefined; this.initializing = undefined;
|
|
136
133
|
void this.initialize();
|
|
137
134
|
}
|
|
138
135
|
if (changed.has('disabled')) {
|
|
139
136
|
this.editor?.setEditable(!this.disabled, false);
|
|
140
|
-
if (this.disabled) void this.
|
|
137
|
+
if (this.disabled) void this.picker.close(false);
|
|
141
138
|
}
|
|
142
139
|
if (changed.has('value') && this.editor && JSON.stringify(this.value) !== this.serializedValue) {
|
|
143
|
-
void this.
|
|
140
|
+
void this.picker.close(false);
|
|
144
141
|
this.editor.commands.setContent(referenceDocument(this.value), false);
|
|
145
142
|
this.serializedValue = JSON.stringify(this.value);
|
|
146
143
|
}
|
|
@@ -152,78 +149,13 @@ export class DeesInputReference extends DeesElement {
|
|
|
152
149
|
|
|
153
150
|
public focus(options?: FocusOptions): void { this.editor?.view.dom.focus(options); }
|
|
154
151
|
|
|
155
|
-
private detectTrigger(): void {
|
|
156
|
-
const editor = this.editor;
|
|
157
|
-
if (!editor || this.disabled || this.popup || !this.searchReferences || !this.trigger || editor.view.composing || !editor.isFocused) return;
|
|
158
|
-
const { from, to, $from } = editor.state.selection;
|
|
159
|
-
if (from !== to || $from.parentOffset < this.trigger.length) return;
|
|
160
|
-
if ($from.parent.textBetween($from.parentOffset - this.trigger.length, $from.parentOffset, '', '\ufffc') !== this.trigger) return;
|
|
161
|
-
this.referenceRange = { from: from - this.trigger.length, to };
|
|
162
|
-
void this.openPicker();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private positionPicker(): void {
|
|
166
|
-
if (!this.editor || !this.popup || !this.referenceRange) return;
|
|
167
|
-
const coords = this.editor.view.coordsAtPos(this.referenceRange.to);
|
|
168
|
-
// The text around the caret, which a scroll in the editor moves along
|
|
169
|
-
const { node } = this.editor.view.domAtPos(this.referenceRange.to);
|
|
170
|
-
this.popup.triggerElement = node instanceof HTMLElement ? node : node.parentElement;
|
|
171
|
-
this.popup.triggerRect = new DOMRect(coords.left, coords.top, 340, coords.bottom - coords.top);
|
|
172
|
-
this.popup.opensToTop = window.innerHeight - coords.bottom < 300 && coords.top > window.innerHeight - coords.bottom;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private async openPicker(): Promise<void> {
|
|
176
|
-
const popup = this.popup = new DeesInputDropdownPopup();
|
|
177
|
-
popup.ownerComponent = this;
|
|
178
|
-
popup.searchLabel = this.searchLabel || this.t('reference.search');
|
|
179
|
-
provideOverlayI18n(popup, { i18n: this.t.i18n });
|
|
180
|
-
popup.searchOptions = async (query, signal) => (await this.searchReferences!(query, signal))
|
|
181
|
-
.map(reference => ({ key: reference.id, option: reference.label, payload: reference }));
|
|
182
|
-
this.positionPicker();
|
|
183
|
-
popup.addEventListener('reposition-request', () => this.positionPicker());
|
|
184
|
-
popup.addEventListener('close-request', () => { void this.closePicker(true); });
|
|
185
|
-
popup.addEventListener('keydown', (event: KeyboardEvent) => {
|
|
186
|
-
if (event.key === 'Tab') { event.preventDefault(); void this.closePicker(true); }
|
|
187
|
-
});
|
|
188
|
-
popup.addEventListener('option-selected', (event: Event) => {
|
|
189
|
-
const reference = (event as CustomEvent<{ payload: IInputReference }>).detail.payload;
|
|
190
|
-
const range = this.referenceRange;
|
|
191
|
-
if (range && this.editor && !this.disabled) {
|
|
192
|
-
this.editor.chain().setMeta('preventReferenceTrigger', true).insertContentAt(range, [
|
|
193
|
-
{ type: 'catalogReference', attrs: reference }, { type: 'text', text: ' ' },
|
|
194
|
-
]).run();
|
|
195
|
-
}
|
|
196
|
-
void this.closePicker(true);
|
|
197
|
-
});
|
|
198
|
-
this.popupOpening = popup.show();
|
|
199
|
-
try {
|
|
200
|
-
await this.popupOpening;
|
|
201
|
-
if (this.popup === popup && this.isConnected && !this.disabled) await popup.focusSearchInput();
|
|
202
|
-
} catch (error) {
|
|
203
|
-
this.loadError = error instanceof Error ? error.message : this.t('reference.searchFailed');
|
|
204
|
-
void this.closePicker(false);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private async closePicker(restoreFocus: boolean): Promise<void> {
|
|
209
|
-
const popup = this.popup;
|
|
210
|
-
const editor = this.editor;
|
|
211
|
-
const opening = this.popupOpening;
|
|
212
|
-
this.popup = undefined;
|
|
213
|
-
this.referenceRange = undefined;
|
|
214
|
-
if (!popup) return;
|
|
215
|
-
await opening?.catch(() => undefined);
|
|
216
|
-
await popup.hide();
|
|
217
|
-
if (restoreFocus && this.isConnected && !this.disabled && this.editor === editor) editor?.commands.focus();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
152
|
private openReference(reference: IInputReference): void {
|
|
221
153
|
this.dispatchEvent(new CustomEvent('reference-open', { detail: reference, bubbles: true, composed: true }));
|
|
222
154
|
}
|
|
223
155
|
|
|
224
156
|
public async disconnectedCallback(): Promise<void> {
|
|
225
157
|
this.connection++;
|
|
226
|
-
void this.
|
|
158
|
+
void this.picker.close(false);
|
|
227
159
|
this.editor?.destroy();
|
|
228
160
|
this.editor = undefined;
|
|
229
161
|
this.initializing = undefined;
|
|
@@ -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'))
|
|
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
|
-
|
|
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
|
|
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--) {
|