diff --git a/projects/ngx-meta/api-extractor/ngx-meta.api.md b/projects/ngx-meta/api-extractor/ngx-meta.api.md index 1d411a486..b5aab3125 100644 --- a/projects/ngx-meta/api-extractor/ngx-meta.api.md +++ b/projects/ngx-meta/api-extractor/ngx-meta.api.md @@ -94,7 +94,7 @@ export interface GlobalMetadataImage { } // @internal (undocumented) -export const _HEAD_ELEMENT_UPSERT_OR_REMOVE: InjectionToken<_HeadElementUpsertOrRemove>; +export const _headElementUpsertOrRemove: InjectionToken<_HeadElementUpsertOrRemove>; // @internal (undocumented) export type _HeadElementUpsertOrRemove = (selector: string, element: HTMLElement | null | undefined) => void; diff --git a/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.spec.ts b/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.spec.ts index dfda82afb..573cb11ee 100644 --- a/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.spec.ts +++ b/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.spec.ts @@ -3,7 +3,7 @@ import { TestBed } from '@angular/core/testing' import { HeadElementHarness } from './__tests__/head-element-harness' import { DOCUMENT } from '@angular/common' import { - _HEAD_ELEMENT_UPSERT_OR_REMOVE, + _headElementUpsertOrRemove, _HeadElementUpsertOrRemove, } from './head-element-upsert-or-remove' @@ -95,5 +95,5 @@ describe('Head element upsert or remove', () => { function makeSut() { TestBed.configureTestingModule({}) - return TestBed.inject(_HEAD_ELEMENT_UPSERT_OR_REMOVE) + return TestBed.inject(_headElementUpsertOrRemove()) } diff --git a/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.ts b/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.ts index 3631c9d44..456e1bf58 100644 --- a/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.ts +++ b/projects/ngx-meta/src/core/src/head-elements/head-element-upsert-or-remove.ts @@ -1,28 +1,28 @@ -import { inject, InjectionToken } from '@angular/core' +import { inject } from '@angular/core' import { DOCUMENT } from '@angular/common' -import { _isDefined } from '../utils' +import { _isDefined, _LazyInjectionToken, _makeInjectionToken } from '../utils' /** * @internal */ -export const _HEAD_ELEMENT_UPSERT_OR_REMOVE = - new InjectionToken<_HeadElementUpsertOrRemove>( +export const _headElementUpsertOrRemove: _LazyInjectionToken< + _HeadElementUpsertOrRemove +> = () => + _makeInjectionToken( ngDevMode ? 'NgxMeta head element upsert or remove util' : 'NgxMetaHEUOR', - { - factory: () => { - const head = inject(DOCUMENT).head - return (selector: string, element: HTMLElement | null | undefined) => { - const existingScriptElement = head.querySelector(selector) - if (existingScriptElement) { - head.removeChild(existingScriptElement) - } + () => { + const head = inject(DOCUMENT).head + return (selector, element) => { + const existingScriptElement = head.querySelector(selector) + if (existingScriptElement) { + head.removeChild(existingScriptElement) + } - if (!_isDefined(element)) { - return - } - head.appendChild(element) + if (!_isDefined(element)) { + return } - }, + head.appendChild(element) + } }, ) diff --git a/projects/ngx-meta/src/core/src/head-elements/index.ts b/projects/ngx-meta/src/core/src/head-elements/index.ts index 9af1fc0fa..c4b4e16a1 100644 --- a/projects/ngx-meta/src/core/src/head-elements/index.ts +++ b/projects/ngx-meta/src/core/src/head-elements/index.ts @@ -1,4 +1,4 @@ export { - _HEAD_ELEMENT_UPSERT_OR_REMOVE, + _headElementUpsertOrRemove, _HeadElementUpsertOrRemove, } from './head-element-upsert-or-remove' diff --git a/projects/ngx-meta/src/json-ld/src/managers/json-ld-metadata-provider.ts b/projects/ngx-meta/src/json-ld/src/managers/json-ld-metadata-provider.ts index 259266dc9..752c959b0 100644 --- a/projects/ngx-meta/src/json-ld/src/managers/json-ld-metadata-provider.ts +++ b/projects/ngx-meta/src/json-ld/src/managers/json-ld-metadata-provider.ts @@ -1,6 +1,6 @@ import { DOCUMENT } from '@angular/common' import { - _HEAD_ELEMENT_UPSERT_OR_REMOVE, + _headElementUpsertOrRemove, _HeadElementUpsertOrRemove, _isDefined, makeMetadataManagerProviderFromSetterFactory, @@ -33,7 +33,7 @@ export const JSON_LD_METADATA_PROVIDER = makeMetadataManagerProviderFromSetterFactory( JSON_LD_METADATA_SETTER_FACTORY, { - d: [_HEAD_ELEMENT_UPSERT_OR_REMOVE, DOCUMENT], + d: [_headElementUpsertOrRemove(), DOCUMENT], jP: [KEY], }, ) diff --git a/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.spec.ts b/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.spec.ts index 2d9098684..433df9f70 100644 --- a/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.spec.ts +++ b/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.spec.ts @@ -1,6 +1,6 @@ import { enableAutoSpy } from '@/ngx-meta/test/enable-auto-spy' import { - _HEAD_ELEMENT_UPSERT_OR_REMOVE, + _headElementUpsertOrRemove, _HeadElementUpsertOrRemove, _URL_RESOLVER, _UrlResolver, @@ -105,7 +105,7 @@ const makeSut = ( TestBed.configureTestingModule({ providers: [ { - provide: _HEAD_ELEMENT_UPSERT_OR_REMOVE, + provide: _headElementUpsertOrRemove(), useValue: opts.headElementUpsertOrRemove ?? jasmine.createSpy('Head element upsert or remove'), diff --git a/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.ts b/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.ts index 391ac1624..832fb3efd 100644 --- a/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.ts +++ b/projects/ngx-meta/src/standard/src/managers/standard-canonical-url-metadata-provider.ts @@ -1,7 +1,7 @@ import { makeStandardMetadataProvider } from '../utils/make-standard-metadata-provider' import { _GLOBAL_CANONICAL_URL, - _HEAD_ELEMENT_UPSERT_OR_REMOVE, + _headElementUpsertOrRemove, _HeadElementUpsertOrRemove, _isDefined, _maybeNonHttpUrlDevMessage, @@ -45,7 +45,7 @@ export const STANDARD_CANONICAL_URL_METADATA_PROVIDER = makeStandardMetadataProvider(_GLOBAL_CANONICAL_URL, { g: _GLOBAL_CANONICAL_URL, s: STANDARD_CANONICAL_URL_SETTER_FACTORY, - d: [_HEAD_ELEMENT_UPSERT_OR_REMOVE, DOCUMENT, _URL_RESOLVER], + d: [_headElementUpsertOrRemove(), DOCUMENT, _URL_RESOLVER], }) const LINK_TAG = 'link'