-
Notifications
You must be signed in to change notification settings - Fork 2.9k
UFM: Add umbElementName component
#23162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
629068a
feat(ufm): add umbElementName UFM component
leekelleher 2230b69
fix(ufm): clear stale value and destroy resolvers in element-name ele…
leekelleher d7db310
Update src/Umbraco.Web.UI.Client/src/packages/ufm/components/element-…
leekelleher 2f64301
test(ufm): add umbElementName parsing test to marked-ufm.test.ts
leekelleher 36f4f7c
Merge branch 'main' into v18/feature/ufm-element-name
leekelleher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export { UmbElementItemRepository } from './repository/index.js'; | ||
| export * from './data-resolver/element-item-data-resolver.js'; |
14 changes: 14 additions & 0 deletions
14
src/Umbraco.Web.UI.Client/src/packages/ufm/components/element-name/element-name.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { UfmToken } from '../../plugins/types.js'; | ||
| import { UmbUfmComponentBase } from '../ufm-component-base.js'; | ||
|
|
||
| import './element-name.element.js'; | ||
|
|
||
| export class UmbUfmElementNameComponent extends UmbUfmComponentBase { | ||
| render(token: UfmToken) { | ||
| if (!token.text) return; | ||
| const attributes = super.getAttributes(token.text); | ||
| return `<ufm-element-name ${attributes}></ufm-element-name>`; | ||
| } | ||
| } | ||
|
|
||
| export { UmbUfmElementNameComponent as api }; |
68 changes: 68 additions & 0 deletions
68
src/Umbraco.Web.UI.Client/src/packages/ufm/components/element-name/element-name.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { UmbUfmElementBase } from '../ufm-element-base.js'; | ||
| import { UMB_UFM_RENDER_CONTEXT } from '../ufm-render/ufm-render.context.js'; | ||
| import { customElement, property } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbElementItemDataResolver, UmbElementItemRepository } from '@umbraco-cms/backoffice/element'; | ||
| import { UmbId } from '@umbraco-cms/backoffice/id'; | ||
|
|
||
| @customElement('ufm-element-name') | ||
| export class UmbUfmElementNameElement extends UmbUfmElementBase { | ||
| #repository?: UmbElementItemRepository; | ||
|
|
||
| @property() | ||
| alias?: string; | ||
|
|
||
| constructor() { | ||
| super(); | ||
|
|
||
| this.consumeContext(UMB_UFM_RENDER_CONTEXT, (context) => { | ||
| this.observe( | ||
| context?.value, | ||
| async (value) => { | ||
| const temp = | ||
| this.alias && typeof value === 'object' | ||
| ? (value as Record<string, unknown>)[this.alias] | ||
| : (value as unknown); | ||
|
Check warning on line 24 in src/Umbraco.Web.UI.Client/src/packages/ufm/components/element-name/element-name.element.ts
|
||
|
|
||
| if (!temp) return; | ||
|
|
||
| const uniques = this.#getUniques(temp); | ||
| this.value = await this.#getNames(uniques); | ||
| }, | ||
| 'observeValue', | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #getUniques(value: unknown) { | ||
| if (Array.isArray(value)) { | ||
| return value.map((x) => x.unique ?? x).filter((x) => UmbId.validate(x)); | ||
| } | ||
| return typeof value === 'string' && UmbId.validate(value) ? [value] : []; | ||
| } | ||
|
leekelleher marked this conversation as resolved.
|
||
|
|
||
| async #getNames(uniques?: Array<string>) { | ||
| if (uniques?.length) { | ||
| if (!this.#repository) this.#repository = new UmbElementItemRepository(this); | ||
| const { data } = await this.#repository.requestItems(uniques); | ||
|
|
||
| if (Array.isArray(data) && data.length > 0) { | ||
| const namePromises = data.map(async (item) => { | ||
| const resolver = new UmbElementItemDataResolver(this); | ||
| resolver.setData(item); | ||
| return await resolver.getName(); | ||
| }); | ||
|
leekelleher marked this conversation as resolved.
|
||
| const names = await Promise.all(namePromises); | ||
| return names.join(', '); | ||
|
leekelleher marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| export { UmbUfmElementNameElement as element }; | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'ufm-element-name': UmbUfmElementNameElement; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/Umbraco.Web.UI.Client/src/packages/ufm/components/element-name/manifests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { ManifestUfmComponent } from '../../extensions/ufm-component.extension.js'; | ||
|
|
||
| export const manifests: Array<ManifestUfmComponent> = [ | ||
| { | ||
| type: 'ufmComponent', | ||
| alias: 'Umb.Markdown.ElementName', | ||
| name: 'Element Name UFM Component', | ||
| api: () => import('./element-name.component.js'), | ||
| meta: { alias: 'umbElementName' }, | ||
| }, | ||
|
leekelleher marked this conversation as resolved.
|
||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.