Skip to content

Commit 1f84fe4

Browse files
authored
UFM: Adds markedExtension extension-type (#19684)
* Adds `markedExtension` extension-type * Relocates the Component and Filter extension-type interface code files to under "extensions" * Moves `UfmPlugin` type to its own referencable file
1 parent 9baf040 commit 1f84fe4

20 files changed

+116
-50
lines changed

src/Umbraco.Web.UI.Client/src/packages/ufm/components/content-name/content-name.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UfmToken } from '../../plugins/marked-ufm.plugin.js';
1+
import type { UfmToken } from '../../plugins/types.js';
22
import { UmbUfmComponentBase } from '../ufm-component-base.js';
33

44
import './content-name.element.js';

src/Umbraco.Web.UI.Client/src/packages/ufm/components/label-value/label-value.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UfmToken } from '../../plugins/marked-ufm.plugin.js';
1+
import type { UfmToken } from '../../plugins/types.js';
22
import { UmbUfmComponentBase } from '../ufm-component-base.js';
33

44
import './label-value.element.js';

src/Umbraco.Web.UI.Client/src/packages/ufm/components/link/link.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UfmToken } from '../../plugins/marked-ufm.plugin.js';
1+
import type { UfmToken } from '../../plugins/types.js';
22
import { UmbUfmComponentBase } from '../ufm-component-base.js';
33

44
import './link.element.js';

src/Umbraco.Web.UI.Client/src/packages/ufm/components/localize/localize.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UfmToken } from '../../plugins/marked-ufm.plugin.js';
1+
import type { UfmToken } from '../../plugins/types.js';
22
import { UmbUfmComponentBase } from '../ufm-component-base.js';
33

44
import './localize.element.js';

src/Umbraco.Web.UI.Client/src/packages/ufm/components/manifests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ManifestUfmComponent } from '../ufm-component.extension.js';
1+
import type { ManifestUfmComponent } from '../extensions/ufm-component.extension.js';
22

33
export const manifests: Array<ManifestUfmComponent> = [
44
{

src/Umbraco.Web.UI.Client/src/packages/ufm/components/ufm-component-base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { UfmToken } from '../plugins/marked-ufm.plugin.js';
2-
import type { UmbUfmComponentApi } from '../ufm-component.extension.js';
1+
import type { UfmToken } from '../plugins/types.js';
2+
import type { UmbUfmComponentApi } from '../extensions/ufm-component.extension.js';
33

44
export abstract class UmbUfmComponentBase implements UmbUfmComponentApi {
55
protected getAttributes(text: string): string | null {

src/Umbraco.Web.UI.Client/src/packages/ufm/contexts/ufm.context.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { ufm } from '../plugins/marked-ufm.plugin.js';
2-
import type { UfmPlugin } from '../plugins/marked-ufm.plugin.js';
3-
import type { ManifestUfmComponent } from '../ufm-component.extension.js';
4-
import type { ManifestUfmFilter } from '../ufm-filter.extension.js';
5-
import { DOMPurify, type Config } from '@umbraco-cms/backoffice/external/dompurify';
1+
import type { ManifestUfmFilter } from '../extensions/ufm-filter.extension.js';
2+
import { DOMPurify } from '@umbraco-cms/backoffice/external/dompurify';
63
import { Marked } from '@umbraco-cms/backoffice/external/marked';
74
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
85
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
96
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
107
import { UmbExtensionsApiInitializer } from '@umbraco-cms/backoffice/extension-api';
118
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
9+
import type { Config as DOMPurifyConfig } from '@umbraco-cms/backoffice/external/dompurify';
1210
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
1311
import type { UmbExtensionApiInitializer } from '@umbraco-cms/backoffice/extension-api';
1412

1513
const UmbDomPurify = DOMPurify(window);
16-
const UmbDomPurifyConfig: Config = {
14+
const UmbDomPurifyConfig: DOMPurifyConfig = {
1715
USE_PROFILES: { html: true },
1816
CUSTOM_ELEMENT_HANDLING: {
1917
tagNameCheck: /^(?:ufm|umb|uui)-.*$/,
@@ -52,23 +50,7 @@ export class UmbUfmContext extends UmbContextBase {
5250
constructor(host: UmbControllerHost) {
5351
super(host, UMB_UFM_CONTEXT);
5452

55-
new UmbExtensionsApiInitializer(this, umbExtensionsRegistry, 'ufmComponent', [], undefined, (controllers) => {
56-
UmbMarked.use(
57-
ufm(
58-
controllers
59-
.map((controller) => {
60-
const ctrl = controller as unknown as UmbExtensionApiInitializer<ManifestUfmComponent>;
61-
if (!ctrl.manifest || !ctrl.api) return;
62-
return {
63-
alias: ctrl.manifest.meta.alias || ctrl.manifest.alias,
64-
marker: ctrl.manifest.meta.marker,
65-
render: ctrl.api.render,
66-
};
67-
})
68-
.filter((x) => x) as Array<UfmPlugin>,
69-
),
70-
);
71-
});
53+
new UmbExtensionsApiInitializer(this, umbExtensionsRegistry, 'markedExtension', [UmbMarked]);
7254

7355
new UmbExtensionsApiInitializer(this, umbExtensionsRegistry, 'ufmFilter', [], undefined, (controllers) => {
7456
const filters = controllers
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ManifestMarkedExtension } from './marked-extension.extension.js';
2+
3+
export const manifests: Array<ManifestMarkedExtension> = [
4+
{
5+
type: 'markedExtension',
6+
alias: 'Umb.MarkedExtension.Ufm',
7+
name: 'UFM Marked Extension',
8+
api: () => import('./ufm-marked-extension.api.js'),
9+
meta: {
10+
alias: 'ufm',
11+
},
12+
},
13+
];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ManifestApi, UmbApi } from '@umbraco-cms/backoffice/extension-api';
2+
3+
/** @internal */
4+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
5+
export interface UmbMarkedExtensionApi extends UmbApi {}
6+
7+
/** @internal */
8+
export interface MetaMarkedExtension {
9+
alias: string;
10+
}
11+
12+
/**
13+
* @internal
14+
* @description The `markedExtension` extension-type is currently for internal use and should be considered experimental.
15+
*/
16+
export interface ManifestMarkedExtension extends ManifestApi<UmbMarkedExtensionApi> {
17+
type: 'markedExtension';
18+
meta: MetaMarkedExtension;
19+
}
20+
21+
declare global {
22+
interface UmbExtensionManifestMap {
23+
umbMarkedExtension: ManifestMarkedExtension;
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type * from './marked-extension.extension.js';
2+
export type * from './ufm-filter.extension.js';
3+
export type * from './ufm-component.extension.js';
4+
5+
export type { UmbUfmMarkedExtensionApi } from './ufm-marked-extension.api.js';

0 commit comments

Comments
 (0)