@kustomizer/visual-editor 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, inject, Injectable, makeEnvironmentProviders, ViewContainerRef, DestroyRef, input, effect, reflectComponentType, ChangeDetectionStrategy, Component, computed, NgZone, signal, viewChild, output } from '@angular/core';
|
|
3
3
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
4
|
-
import { of, startWith, map, delay, throwError, isObservable, Observable, BehaviorSubject, tap, Subject, filter, debounceTime, switchMap as switchMap$1, takeUntil } from 'rxjs';
|
|
4
|
+
import { of, startWith, map, delay, throwError, isObservable, Observable, BehaviorSubject, tap, Subject, filter, firstValueFrom, debounceTime, switchMap as switchMap$1, takeUntil } from 'rxjs';
|
|
5
5
|
import { switchMap, map as map$1, catchError } from 'rxjs/operators';
|
|
6
6
|
import { HttpClient } from '@angular/common/http';
|
|
7
7
|
import { createActionGroup, emptyProps, props, createReducer, on, createFeatureSelector, createSelector, provideState, Store } from '@ngrx/store';
|
|
@@ -3260,6 +3260,50 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
|
|
|
3260
3260
|
type: Injectable
|
|
3261
3261
|
}], ctorParameters: () => [] });
|
|
3262
3262
|
|
|
3263
|
+
/**
|
|
3264
|
+
* Service that holds and dynamically loads the per-merchant storefront URL.
|
|
3265
|
+
*
|
|
3266
|
+
* Resolution order:
|
|
3267
|
+
* 1. Metafield value loaded from GET /api/storefront-url (per-shop)
|
|
3268
|
+
* 2. Static STOREFRONT_URL injection token (env var / window global fallback)
|
|
3269
|
+
* 3. Empty string (editor works with local components only)
|
|
3270
|
+
*/
|
|
3271
|
+
class StorefrontUrlService {
|
|
3272
|
+
http = inject(HttpClient);
|
|
3273
|
+
staticUrl = inject(STOREFRONT_URL);
|
|
3274
|
+
/** Current storefront URL — reactive signal used by the editor and iframe. */
|
|
3275
|
+
url = signal('', ...(ngDevMode ? [{ debugName: "url" }] : []));
|
|
3276
|
+
/**
|
|
3277
|
+
* Load the storefront URL from the backend metafield.
|
|
3278
|
+
* Falls back to the static STOREFRONT_URL token if the endpoint
|
|
3279
|
+
* returns no value or fails.
|
|
3280
|
+
*
|
|
3281
|
+
* Called during APP_INITIALIZER.
|
|
3282
|
+
*/
|
|
3283
|
+
async load() {
|
|
3284
|
+
try {
|
|
3285
|
+
const res = await firstValueFrom(this.http.get('/api/storefront-url'));
|
|
3286
|
+
if (res.url) {
|
|
3287
|
+
this.url.set(res.url);
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
catch {
|
|
3292
|
+
// Non-fatal — fall back to static token
|
|
3293
|
+
}
|
|
3294
|
+
// Fallback: use the static injection token (env var / window global)
|
|
3295
|
+
if (this.staticUrl) {
|
|
3296
|
+
this.url.set(this.staticUrl);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: StorefrontUrlService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3300
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: StorefrontUrlService, providedIn: 'root' });
|
|
3301
|
+
}
|
|
3302
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: StorefrontUrlService, decorators: [{
|
|
3303
|
+
type: Injectable,
|
|
3304
|
+
args: [{ providedIn: 'root' }]
|
|
3305
|
+
}] });
|
|
3306
|
+
|
|
3263
3307
|
const MAX_DEPTH = 12;
|
|
3264
3308
|
class DragDropService {
|
|
3265
3309
|
store = inject(Store);
|
|
@@ -4391,7 +4435,7 @@ class VisualEditorComponent {
|
|
|
4391
4435
|
config = inject(VISUAL_EDITOR_CONFIG);
|
|
4392
4436
|
dndService = inject(DragDropService);
|
|
4393
4437
|
iframeBridge = inject(IframeBridgeService);
|
|
4394
|
-
|
|
4438
|
+
storefrontUrlService = inject(StorefrontUrlService);
|
|
4395
4439
|
sanitizer = inject(DomSanitizer);
|
|
4396
4440
|
destroy$ = new Subject();
|
|
4397
4441
|
// Configuration-driven UI options
|
|
@@ -4404,9 +4448,10 @@ class VisualEditorComponent {
|
|
|
4404
4448
|
// Iframe preview
|
|
4405
4449
|
previewFrame = viewChild('previewFrame', ...(ngDevMode ? [{ debugName: "previewFrame" }] : []));
|
|
4406
4450
|
previewUrl = computed(() => {
|
|
4407
|
-
|
|
4451
|
+
const url = this.storefrontUrlService.url();
|
|
4452
|
+
if (!url)
|
|
4408
4453
|
return null;
|
|
4409
|
-
return this.sanitizer.bypassSecurityTrustResourceUrl(`${
|
|
4454
|
+
return this.sanitizer.bypassSecurityTrustResourceUrl(`${url}/kustomizer/editor`);
|
|
4410
4455
|
}, ...(ngDevMode ? [{ debugName: "previewUrl" }] : []));
|
|
4411
4456
|
iframeReady = false;
|
|
4412
4457
|
propertiesTab = signal('props', ...(ngDevMode ? [{ debugName: "propertiesTab" }] : []));
|
|
@@ -4673,7 +4718,8 @@ class VisualEditorComponent {
|
|
|
4673
4718
|
onIframeLoad() {
|
|
4674
4719
|
const iframe = this.previewFrame()?.nativeElement;
|
|
4675
4720
|
if (iframe) {
|
|
4676
|
-
const
|
|
4721
|
+
const sfUrl = this.storefrontUrlService.url();
|
|
4722
|
+
const origin = sfUrl ? new URL(sfUrl).origin : '*';
|
|
4677
4723
|
this.iframeBridge.connect(iframe, origin);
|
|
4678
4724
|
}
|
|
4679
4725
|
}
|
|
@@ -7839,5 +7885,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
|
|
|
7839
7885
|
* Generated bundle index. Do not edit.
|
|
7840
7886
|
*/
|
|
7841
7887
|
|
|
7842
|
-
export { BlockTreeItemComponent, CREATE_METAFIELD_DEFINITION_MUTATION, ComponentRegistryService, DEFAULT_ROUTER_NAVIGATION_CONFIG, DEFAULT_VISUAL_EDITOR_CONFIG, DELETE_METAFIELDS_MUTATION, DELETE_METAFIELD_DEFINITION_MUTATION, DefaultRouterNavigationService, DragDropService, DynamicRendererComponent, EDITOR_COMPONENT_DEFINITIONS, FILES_QUERY, GET_METAFIELD_DEFINITION_QUERY, GET_SHOP_ID_QUERY, GET_SHOP_METAFIELD_QUERY$1 as GET_SHOP_METAFIELD_QUERY, INDEX_KEY$1 as INDEX_KEY, IframeBridgeService, InputPageLoadingStrategy, MAX_METAFIELD_SIZE, ManifestLoaderService, NAMESPACE$1 as NAMESPACE, PageLoadingStrategy, PageManagerComponent, PageService, PageShopifyRepository, PageStorefrontRepository, ROUTER_NAVIGATION_CONFIG, RoutePageLoadingStrategy, SET_METAFIELD_MUTATION, SHOPIFY_CONFIG, STOREFRONT_CONFIG, STOREFRONT_URL, ShopifyFilePickerComponent, ShopifyFilesService, ShopifyGraphQLClient, ShopifyMetafieldRepository, SlotRendererComponent, StorefrontGraphQLClient, StorefrontMetafieldRepository, USE_IN_MEMORY_PAGES, VISUAL_EDITOR_CONFIG, VISUAL_EDITOR_FEATURE_KEY, VisualEditor, VisualEditorActions, VisualEditorComponent, VisualEditorFacade, VisualEditorNavigation, initialVisualEditorState, provideEditorComponents, provideVisualEditor, provideVisualEditorStore, selectBlocksForSection, selectBlocksForSlot, selectCanRedo, selectCanUndo, selectCurrentPage, selectCurrentPageId, selectCurrentPageSlug, selectCurrentPageStatus, selectCurrentPageTitle, selectCurrentPageVersion, selectDraggedElementId, selectElementById, selectHistory, selectHistoryIndex, selectHistoryLength, selectIsDirty, selectIsDragging, selectIsPageLoaded, selectLastAction, selectSectionById, selectSections, selectSelectedBlock, selectSelectedBlockSlotName, selectSelectedElement, selectSelectedElementId, selectSelectedElementType, selectSelectedSection, selectSelectedSectionId, selectSelectedSectionType, selectVisualEditorState, visualEditorReducer };
|
|
7888
|
+
export { BlockTreeItemComponent, CREATE_METAFIELD_DEFINITION_MUTATION, ComponentRegistryService, DEFAULT_ROUTER_NAVIGATION_CONFIG, DEFAULT_VISUAL_EDITOR_CONFIG, DELETE_METAFIELDS_MUTATION, DELETE_METAFIELD_DEFINITION_MUTATION, DefaultRouterNavigationService, DragDropService, DynamicRendererComponent, EDITOR_COMPONENT_DEFINITIONS, FILES_QUERY, GET_METAFIELD_DEFINITION_QUERY, GET_SHOP_ID_QUERY, GET_SHOP_METAFIELD_QUERY$1 as GET_SHOP_METAFIELD_QUERY, INDEX_KEY$1 as INDEX_KEY, IframeBridgeService, InputPageLoadingStrategy, MAX_METAFIELD_SIZE, ManifestLoaderService, NAMESPACE$1 as NAMESPACE, PageLoadingStrategy, PageManagerComponent, PageService, PageShopifyRepository, PageStorefrontRepository, ROUTER_NAVIGATION_CONFIG, RoutePageLoadingStrategy, SET_METAFIELD_MUTATION, SHOPIFY_CONFIG, STOREFRONT_CONFIG, STOREFRONT_URL, ShopifyFilePickerComponent, ShopifyFilesService, ShopifyGraphQLClient, ShopifyMetafieldRepository, SlotRendererComponent, StorefrontGraphQLClient, StorefrontMetafieldRepository, StorefrontUrlService, USE_IN_MEMORY_PAGES, VISUAL_EDITOR_CONFIG, VISUAL_EDITOR_FEATURE_KEY, VisualEditor, VisualEditorActions, VisualEditorComponent, VisualEditorFacade, VisualEditorNavigation, initialVisualEditorState, provideEditorComponents, provideVisualEditor, provideVisualEditorStore, selectBlocksForSection, selectBlocksForSlot, selectCanRedo, selectCanUndo, selectCurrentPage, selectCurrentPageId, selectCurrentPageSlug, selectCurrentPageStatus, selectCurrentPageTitle, selectCurrentPageVersion, selectDraggedElementId, selectElementById, selectHistory, selectHistoryIndex, selectHistoryLength, selectIsDirty, selectIsDragging, selectIsPageLoaded, selectLastAction, selectSectionById, selectSections, selectSelectedBlock, selectSelectedBlockSlotName, selectSelectedElement, selectSelectedElementId, selectSelectedElementType, selectSelectedSection, selectSelectedSectionId, selectSelectedSectionType, selectVisualEditorState, visualEditorReducer };
|
|
7843
7889
|
//# sourceMappingURL=kustomizer-visual-editor.mjs.map
|