Skip to content

Commit 33e240e

Browse files
committed
Renders Tiptap toolbar, with rows and groups
1 parent 2f56fa7 commit 33e240e

File tree

1 file changed

+65
-17
lines changed

1 file changed

+65
-17
lines changed

src/packages/rte/tiptap/components/input-tiptap/tiptap-fixed-menu.element.ts

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { ManifestTiptapToolbarExtension } from '../../extensions/tiptap-toolbar-extension.js';
2-
import { css, customElement, html, property } from '@umbraco-cms/backoffice/external/lit';
1+
import { css, customElement, html, map, property, state } from '@umbraco-cms/backoffice/external/lit';
2+
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
3+
import { UmbExtensionsElementAndApiInitializer } from '@umbraco-cms/backoffice/extension-api';
34
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
45
import type { Editor } from '@umbraco-cms/backoffice/external/tiptap';
56
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
@@ -10,6 +11,12 @@ const elementName = 'umb-tiptap-fixed-menu';
1011

1112
@customElement(elementName)
1213
export class UmbTiptapFixedMenuElement extends UmbLitElement {
14+
#attached = false;
15+
#extensionsController?: UmbExtensionsElementAndApiInitializer;
16+
17+
@state()
18+
private _lookup?: Map<string, unknown>;
19+
1320
@property({ type: Boolean, reflect: true })
1421
readonly = false;
1522

@@ -20,43 +27,84 @@ export class UmbTiptapFixedMenuElement extends UmbLitElement {
2027
configuration?: UmbPropertyEditorConfigCollection;
2128

2229
@property({ attribute: false })
23-
toolbar: string[][][] = [[[]]];
30+
toolbar: Array<Array<Array<string>>> = [[[]]];
31+
32+
override connectedCallback(): void {
33+
super.connectedCallback();
34+
this.#attached = true;
35+
this.#observeExtensions();
36+
}
37+
override disconnectedCallback(): void {
38+
this.#attached = false;
39+
this.#extensionsController?.destroy();
40+
this.#extensionsController = undefined;
41+
super.disconnectedCallback();
42+
}
43+
44+
#observeExtensions(): void {
45+
if (!this.#attached) return;
46+
this.#extensionsController?.destroy();
47+
48+
this.#extensionsController = new UmbExtensionsElementAndApiInitializer(
49+
this,
50+
umbExtensionsRegistry,
51+
'tiptapToolbarExtension',
52+
[],
53+
(manifest) => this.toolbar.flat(2).includes(manifest.alias),
54+
(extensionControllers) => {
55+
this._lookup = new Map(extensionControllers.map((ext) => [ext.alias, ext.component]));
56+
},
57+
);
58+
59+
this.#extensionsController.apiProperties = { configuration: this.configuration };
60+
this.#extensionsController.elementProperties = { editor: this.editor, configuration: this.configuration };
61+
}
2462

2563
override render() {
2664
return html`
27-
<umb-extension-with-api-slot
28-
type="tiptapToolbarExtension"
29-
.filter=${(ext: ManifestTiptapToolbarExtension) =>
30-
this.toolbar.flat(2).includes(ext.alias) && (!!ext.kind || !!ext.element)}
31-
.elementProps=${{ editor: this.editor, configuration: this.configuration }}
32-
.apiProps=${{ configuration: this.configuration }}>
33-
</umb-extension-with-api-slot>
65+
${map(
66+
this.toolbar,
67+
(row) => html`
68+
<div class="row">
69+
${map(row, (group) => html`<div class="group">${map(group, (alias) => this._lookup?.get(alias))}</div>`)}
70+
</div>
71+
`,
72+
)}
3473
`;
3574
}
3675

3776
static override readonly styles = css`
77+
:host([readonly]) {
78+
pointer-events: none;
79+
background-color: var(--uui-color-surface-alt);
80+
}
81+
3882
:host {
3983
border-radius: var(--uui-border-radius);
4084
border: 1px solid var(--uui-color-border);
4185
border-bottom-left-radius: 0;
4286
border-bottom-right-radius: 0;
4387
background-color: var(--uui-color-surface);
4488
color: var(--color-text);
45-
display: grid;
46-
grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
47-
gap: var(--uui-size-space-1);
89+
display: flex;
90+
flex-direction: column;
4891
position: sticky;
4992
top: -25px;
5093
left: 0px;
5194
right: 0px;
5295
padding: var(--uui-size-space-3);
53-
align-items: center;
5496
z-index: 9999999;
5597
}
5698
57-
:host([readonly]) {
58-
pointer-events: none;
59-
background-color: var(--uui-color-surface-alt);
99+
.row {
100+
display: flex;
101+
flex-direction: row;
102+
gap: var(--uui-size-space-3);
103+
}
104+
105+
.group {
106+
display: flex;
107+
flex-direction: row;
60108
}
61109
`;
62110
}

0 commit comments

Comments
 (0)