UNPKG

@adobe/genstudio-extensibility-sdk

Version:
95 lines (94 loc) 3.97 kB
/* Copyright 2026 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ export class FragmentSwapExtensionServiceError extends Error { constructor(message) { super(message); this.name = "FragmentSwapExtensionServiceError"; } } /** * Manages swap field extension functionality for swapping field content */ export class FragmentSwapExtensionService { /** * Gets the current field context from the host * @param connection - The guest connection to the host * @returns Promise<SwapFieldContext> The current field context * @throws Error if connection is missing */ static async getExperience(connection) { if (!connection) { throw new FragmentSwapExtensionServiceError("Connection is required to get experience"); } try { // @ts-ignore Remote API is handled through postMessage return await connection.host.api.fragmentSwapExtension.getExperience(); } catch (error) { throw new FragmentSwapExtensionServiceError("Failed to get experience from host"); } } /** * Gets the generation context from the host * @param connection - The guest connection to the host * @returns Promise<GenerationContext> The generation context * @throws Error if connection is missing */ static async getGenerationContext(connection) { if (!connection) { throw new FragmentSwapExtensionServiceError("Connection is required to get generation context"); } try { // @ts-ignore Remote API is handled through postMessage return await connection.host.api.fragmentSwapExtension.getGenerationContext(); } catch (error) { throw new FragmentSwapExtensionServiceError("Failed to get generation context from host"); } } /** * Gets the field currently being swapped, including its name and current value * @param connection - The guest connection to the host * @returns Promise<FieldUpdate> The selected field's experienceId, name, and current value * @throws Error if connection is missing */ static async getSelectedField(connection) { if (!connection) { throw new FragmentSwapExtensionServiceError("Connection is required to get selected field"); } try { // @ts-ignore Remote API is handled through postMessage return await connection.host.api.fragmentSwapExtension.getSelectedField(); } catch (error) { throw new FragmentSwapExtensionServiceError("Failed to get selected field from host"); } } /** * Sets the swap value for the field content * @param connection - The guest connection to the host * @param value - The new value to write into the field * @throws Error if connection is missing */ static setSwapValue(connection, value) { if (!connection) { throw new FragmentSwapExtensionServiceError("Connection is required to set swap value"); } try { // @ts-ignore Remote API is handled through postMessage connection.host.api.fragmentSwapExtension.setSwapValue(value); } catch (error) { throw new FragmentSwapExtensionServiceError("Failed to set swap value"); } } } //# sourceMappingURL=fragment-swap-extension-service.js.map