Skip to content

Commit 826e601

Browse files
authored
Merge branch 'main' into v14/chore/check-paths-in-dist-cms
2 parents 6e9a155 + 7c57102 commit 826e601

File tree

13 files changed

+84
-43
lines changed

13 files changed

+84
-43
lines changed

.github/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
This is the working repository of the upcoming new Backoffice to Umbraco CMS.
44

5+
[![Build and test](https://github.com/umbraco/Umbraco.CMS.Backoffice/actions/workflows/build_test.yml/badge.svg)](https://github.com/umbraco/Umbraco.CMS.Backoffice/actions/workflows/build_test.yml)
56
[![Storybook](https://github.com/umbraco/Umbraco.CMS.Backoffice/actions/workflows/azure-static-web-apps-ambitious-stone-0033b3603.yml/badge.svg)](https://github.com/umbraco/Umbraco.CMS.Backoffice/actions/workflows/azure-static-web-apps-ambitious-stone-0033b3603.yml)
7+
[![SonarCloud](https://sonarcloud.io/api/project_badges/measure?project=umbraco_Umbraco.CMS.Backoffice&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=umbraco_Umbraco.CMS.Backoffice)
68

79
## Installation instructions
810

sonar-project.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Define the same root directory for sources and tests
2+
sonar.sources = src/
3+
sonar.tests = src/
4+
5+
# Include test files in the test scope
6+
sonar.test.inclusions = src/**/*.test.ts
7+
8+
# Exclude test and stories files from the source scope
9+
sonar.exclusions = src/**/*.test.ts, src/**/*.stories.ts

src/packages/core/components/table/table.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class UmbTableElement extends LitElement {
279279
const element = document.createElement('umb-ufm-render') as UmbUfmRenderElement;
280280
element.inline = true;
281281
element.markdown = column.labelTemplate;
282-
element.value = value;
282+
element.value = { value };
283283
return element;
284284
}
285285

src/packages/core/extension-registry/models/ufm-component.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ManifestApi, UmbApi } from '@umbraco-cms/backoffice/extension-api';
2-
import type { Tokens } from '@umbraco-cms/backoffice/external/marked';
2+
import type { UfmToken } from '@umbraco-cms/backoffice/ufm';
33

44
export interface UmbUfmComponentApi extends UmbApi {
5-
render(token: Tokens.Generic): string | undefined;
5+
render(token: UfmToken): string | undefined;
66
}
77

88
export interface MetaUfmComponent {

src/packages/documents/documents/collection/views/grid/document-grid-collection-view.element.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,26 @@ export class UmbDocumentGridCollectionViewElement extends UmbLitElement {
172172
${repeat(
173173
this._userDefinedProperties,
174174
(column) => column.alias,
175-
(column) => html`
176-
<li>
177-
<span>${column.header}:</span>
178-
${when(
179-
column.nameTemplate,
180-
() => html`
181-
<umb-ufm-render
182-
inline
183-
.markdown=${column.nameTemplate}
184-
.value=${getPropertyValueByAlias(item, column.alias)}></umb-ufm-render>
185-
`,
186-
() => html`${getPropertyValueByAlias(item, column.alias)}`,
187-
)}
188-
</li>
189-
`,
175+
(column) => this.#renderProperty(item, column),
190176
)}
191177
</ul>
192178
`;
193179
}
194180

181+
#renderProperty(item: UmbDocumentCollectionItemModel, column: UmbCollectionColumnConfiguration) {
182+
const value = getPropertyValueByAlias(item, column.alias);
183+
return html`
184+
<li>
185+
<span>${column.header}:</span>
186+
${when(
187+
column.nameTemplate,
188+
() => html`<umb-ufm-render inline .markdown=${column.nameTemplate} .value=${{ value }}></umb-ufm-render>`,
189+
() => html`${value}`,
190+
)}
191+
</li>
192+
`;
193+
}
194+
195195
static override styles = [
196196
UmbTextStyles,
197197
css`

src/packages/ufm/components/ufm-render/ufm-render.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ UmbDomPurify.addHook('afterSanitizeAttributes', function (node) {
2828
}
2929
});
3030

31-
const UmbMarked = new Marked({
31+
export const UmbMarked = new Marked({
3232
async: true,
3333
gfm: true,
3434
breaks: true,

src/packages/ufm/manifests.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ export const manifests: Array<ManifestUfmComponent> = [
44
{
55
type: 'ufmComponent',
66
alias: 'Umb.Markdown.LabelValue',
7-
name: 'Label Value Markdown Component',
7+
name: 'Label Value UFM Component',
88
api: () => import('./ufm-components/label-value.component.js'),
9-
meta: {
10-
marker: '=',
11-
},
9+
meta: { marker: '=' },
1210
},
1311
{
1412
type: 'ufmComponent',
1513
alias: 'Umb.Markdown.Localize',
16-
name: 'Localize Markdown Component',
14+
name: 'Localize UFM Component',
1715
api: () => import('./ufm-components/localize.component.js'),
18-
meta: {
19-
marker: '#',
20-
},
16+
meta: { marker: '#' },
2117
},
2218
];

src/packages/ufm/plugins/marked-ufm.plugin.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type { MarkedExtension, Tokens } from '@umbraco-cms/backoffice/external/m
33
export interface UfmPlugin {
44
alias: string;
55
marker: string;
6-
render?: (token: Tokens.Generic) => string | undefined;
6+
render?: (token: UfmToken) => string | undefined;
7+
}
8+
9+
export interface UfmToken extends Tokens.Generic {
10+
text?: string;
711
}
812

913
export function ufm(plugins: Array<UfmPlugin> = []): MarkedExtension {
@@ -12,13 +16,9 @@ export function ufm(plugins: Array<UfmPlugin> = []): MarkedExtension {
1216
return {
1317
name: alias,
1418
level: 'inline',
15-
start: (src: string) => {
16-
const regex = new RegExp(`\\{${marker}`);
17-
const match = src.match(regex);
18-
return match ? match.index : -1;
19-
},
20-
tokenizer(src: string): Tokens.Generic | undefined {
21-
const pattern = `^(?<!\\\\){{?${marker}((?:[a-zA-Z][\\w-]*|[\\{].*?[\\}]+|[\\[].*?[\\]])+)(?<!\\\\)}}?`;
19+
start: (src: string) => src.indexOf(`{${marker}`),
20+
tokenizer: (src: string) => {
21+
const pattern = `^\\{${marker}([^}]*)\\}`;
2222
const regex = new RegExp(pattern);
2323
const match = src.match(regex);
2424

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect } from '@open-wc/testing';
2+
import { ufm } from './marked-ufm.plugin.js';
3+
import { UmbMarked } from '../index.js';
4+
import { UmbUfmLabelValueComponent } from '../ufm-components/label-value.component.js';
5+
import { UmbUfmLocalizeComponent } from '../ufm-components/localize.component.js';
6+
7+
describe('UmbMarkedUfm', () => {
8+
describe('UFM parsing', () => {
9+
const runs = [
10+
{ ufm: '{=prop1}', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
11+
{ ufm: '{= prop1}', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
12+
{ ufm: '{= prop1 }', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
13+
{ ufm: '{{=prop1}}', expected: '{<ufm-label-value alias="prop1"></ufm-label-value>}' },
14+
{ ufm: '{#general_add}', expected: '<umb-localize key="general_add"></umb-localize>' },
15+
];
16+
17+
// Manually configuring the UFM components for testing.
18+
UmbMarked.use(
19+
ufm([
20+
{ alias: 'Umb.Markdown.LabelValue', marker: '=', render: new UmbUfmLabelValueComponent().render },
21+
{ alias: 'Umb.Markdown.Localize', marker: '#', render: new UmbUfmLocalizeComponent().render },
22+
]),
23+
);
24+
25+
runs.forEach((run) => {
26+
it(`Parsing "${run.ufm}"`, async () => {
27+
const markup = await UmbMarked.parseInline(run.ufm);
28+
expect(markup).to.equal(run.expected);
29+
});
30+
});
31+
});
32+
});

src/packages/ufm/ufm-components/label-value.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { UfmToken } from '../plugins/marked-ufm.plugin.js';
12
import { UmbUfmComponentBase } from './ufm-component-base.js';
2-
import type { Tokens } from '@umbraco-cms/backoffice/external/marked';
33

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

66
export class UmbUfmLabelValueComponent extends UmbUfmComponentBase {
7-
render(token: Tokens.Generic) {
7+
render(token: UfmToken) {
8+
if (!token.text) return;
89
return `<ufm-label-value alias="${token.text}"></ufm-label-value>`;
910
}
1011
}

0 commit comments

Comments
 (0)