Skip to main content

index

Myop Logo

Myop SDK

Dynamic UI component management for modern web applications

npm versionnpm downloadsDiscord

Documentation | Website | Discord


What is Myop?

Myop is an open-source SDK that enables real-time UI modifications without deployments. It bridges your application logic with dynamically swappable user interfaces, allowing developers to:

  • Experiment with UI/UX changes instantly
  • Refactor component appearance without touching core functionality
  • Maintain typed communication between components and host applications
  • Load and manage UI components dynamically at runtime

Installation

npm install @myop/sdk

Or via CDN:

<script src="https://cdn.myop.dev/sdk/next/myop_sdk.min.js"></script>

Quick Start

Using npm/ESM

import { getHostModule } from '@myop/sdk';

// Initialize the SDK
const { hostSDK } = await getHostModule();
hostSDK.init();

// Load a component
const component = await hostSDK.loadComponent(componentConfig, containerElement);
await component.initiated();

Using CDN

<script src="https://cdn.myop.dev/sdk/next/myop_sdk.min.js"></script>
<script>
const { hostSDK } = await window.myop.rootSDK.getHostModule();
hostSDK.init();

const component = await hostSDK.loadComponent(config, document.getElementById('app'));
await component.initiated();
</script>

Architecture

The Myop SDK is modular, consisting of several specialized packages:

ModuleDescriptionImport
Host SDKCore module for embedding and managing Myop components@myop/sdk or @myop/sdk/host
Iframe SDKSecure isolation for components in iframes@myop/sdk/iframe
WebComponent SDKSupport for self-contained web components@myop/sdk/webcomponent
MessagesType-safe communication between host and components@myop/sdk/messages
HelpersUtility functions and configuration builders@myop/sdk/helpers

Framework Integration

Myop provides official framework packages for seamless integration:

PackageInstall
Reactnpm install @myop/react
Vue.jsnpm install @myop/vue
Angularnpm install @myop/angular
React
npm install @myop/react
import { MyopComponent } from '@myop/react';

function App() {
return (
<MyopComponent
componentId="your-component-id"
environment="production"
data={{ user: 'John' }}
onLoad={(component) => console.log('Component loaded', component)}
onError={(error) => console.error('Error:', error)}
on={(action, payload) => {
// Handle CTA actions from the component
console.log('Action:', action, payload);
}}
loader={<div>Loading...</div>}
fallback={<div>Failed to load</div>}
/>
);
}

Props:

PropTypeDescription
componentIdstringComponent ID from Myop Cloud
environmentstringEnvironment identifier (default: "production")
dataanyData passed to myop_init_interface
onLoad(component) => voidCalled when component loads
onError(error) => voidCalled on error
on(action, payload) => voidHandler for myop_cta_handler calls
loaderReactNodeCustom loading indicator
fallbackReactNodeCustom error fallback
fadeDurationnumberLoader fade duration in ms

Preloading:

import { preload, isPreloaded } from '@myop/react';

// Preload components for faster rendering
await preload(['component-1', 'component-2'], 'production');

// Check if already loaded
if (isPreloaded('component-1')) {
// Component will render instantly
}

Local Development:

import { enableLocalDev } from '@myop/react';

// Point to local server
enableLocalDev();
Vue.js
npm install @myop/vue
<template>
<MyopContainer
:componentId="componentId"
:flowId="flowId"
@ready="onReady"
v-bind="$attrs"
>
<template #loading>
<div>Loading...</div>
</template>
</MyopContainer>
</template>

<script setup lang="ts">
import { MyopContainer } from '@myop/vue';
import type { IMyopComponent } from '@myop/sdk/host';

const componentId = 'your-component-id';
const flowId = 'optional-flow-id';

const onReady = (component: IMyopComponent, innerRef?: any) => {
console.log('Component loaded', component);
};
</script>

Props:

PropTypeDescription
componentIdstringComponent ID from Myop Cloud
flowIdstring?Optional flow ID
onReady(component, innerRef?) => voidCalled when component loads

Slots:

SlotDescription
loadingShown while component loads
Angular
npm install @myop/angular
import { Component } from '@angular/core';
import { MyopContainerComponent } from '@myop/angular';
import type { IMyopComponent } from '@myop/sdk/host';

@Component({
selector: 'app-root',
standalone: true,
imports: [MyopContainerComponent],
template: `
<myop-container
[componentId]="componentId"
[flowId]="flowId"
[inputs]="inputs"
(componentReady)="onComponentReady($event)"
>
<!-- Content shown while loading -->
<div>Loading...</div>
</myop-container>
`
})
export class AppComponent {
componentId = 'your-component-id';
flowId?: string;
inputs = { theme: 'dark' };

onComponentReady(component: IMyopComponent) {
console.log('Component loaded', component);
}
}

Inputs:

InputTypeDescription
componentIdstringComponent ID from Myop Cloud
flowIdstring?Optional flow ID
inputsobjectData passed to the component

Outputs:

OutputTypeDescription
componentReadyIMyopComponentEmitted when component loads
Vanilla JavaScript / CDN
<div id="myop-container"></div>

<script src="https://cdn.myop.dev/sdk/next/myop_sdk.min.js"></script>
<script>
async function init() {
const { hostSDK } = await window.myop.rootSDK.getHostModule();
const { CloudRepository } = await window.myop.rootSDK.getMyopHelpers();

const container = document.getElementById('myop-container');

// ============ V1: User Flows ============
// Fetch from auto-generated flow
const configV1 = await CloudRepository.Main.fetchComponentV1('component-id');
await hostSDK.loadComponent(configV1, container);

// Or fetch from a specific flow
const configFromFlow = await CloudRepository.Main.fetchComponentV1('component-id', 'flow-id');

// ============ V2: Direct Variant Loading ============
// Fetch variant directly by component ID and environment
const variantV2 = await CloudRepository.Main.fetchComponentV2('component-id', 'production');
await hostSDK.loadComponent(variantV2, container);
}

init();
</script>

API Reference

CloudRepository

Fetch component configurations from Myop Cloud:

import { CloudRepository } from '@myop/sdk/helpers';

// Fetch a component (v1 - from user flows)
const componentConfig = await CloudRepository.Main.fetchComponent('component-id');

// Fetch a component from a specific flow
const componentConfig = await CloudRepository.Main.fetchComponent('component-id', 'flow-id');

// Fetch a v2 component variant
const variantConfig = await CloudRepository.Main.fetchComponentV2('component-id', 'environment');

// Fetch a complete user flow
const flow = await CloudRepository.Main.fetchFlow('flow-id');

// Check if a component is preloaded
const isLoaded = CloudRepository.Main.isPreloaded('component-id');

Host SDK

import { getHostModule } from '@myop/sdk';

const { hostSDK } = await getHostModule();

// Load a component into a container
const component = await hostSDK.loadComponent(componentConfig, containerElement);

// Load with options
const component = await hostSDK.loadComponent(componentConfig, container, {
hidden: false, // Start hidden
connectProps: true, // Auto-connect props (default: true)
timeout: 5000, // Initialization timeout
hooks: { // Lifecycle hooks
afterSkinSelected: async (skin) => skin
}
});

// Navigate to a different component
const newComponent = await hostSDK.navigate(currentComponent, newConfig, {
staged: true, // Load new component before disposing old one
});

// Send messages to component
component.send(message);

// Dispose component
component.dispose();

ComponentConfig Builder

Build component configurations programmatically:

import { ComponentConfig, SkinConfig } from '@myop/sdk/helpers';

const skin = SkinConfig.create()
.withHTMLLoader({
HTML: '<div>My Component</div>',
shadowRootMode: 'open'
})
.build();

const config = ComponentConfig.create()
.withName('my-component')
.withDefaultSkin(skin)
.withBasicRef('header')
.withBasicRef('content')
.build();

Iframe SDK

For components running inside iframes:

import { getIframeModule } from '@myop/sdk';

const { IframeSDK } = await getIframeModule();

WebComponent SDK

For self-contained web components:

import { getWebcomponentModule } from '@myop/sdk';

const { WebComponentSDK } = await getWebcomponentModule();

Documentation

For comprehensive documentation, guides, and examples, visit docs.myop.dev.

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Run tests
npm test

# Build for production
npm run build

# Generate documentation
npm run build:docs

License

This project is licensed under the MIT License.


Made with care by the Myop team