mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 13:45:13 +08:00
106a5d36ed
* Implement StreamEmbed instance and rename library to coral * Add article & articleButton.html, only show embed htmls in production * Respect assetURL * Add tests * Add parseHashQuery * Fix permalink query and integration tests * Fix permalink URL * Remove optionalparams from pym * Scroll when showing permalink view * Implement autoRender * AutoRender immediately when render permalink * Add test for `showPermalink` event * Add comment
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import pym from "pym.js";
|
|
|
|
import { CleanupCallback, Decorator } from "./decorators";
|
|
|
|
export interface PymControlConfig {
|
|
id: string;
|
|
url: string;
|
|
title: string;
|
|
decorators?: ReadonlyArray<Decorator>;
|
|
}
|
|
|
|
export type PymControlFactory = (config: PymControlConfig) => PymControl;
|
|
|
|
export const defaultPymControlFactory: PymControlFactory = config =>
|
|
new PymControl(config);
|
|
|
|
export default class PymControl {
|
|
private pym: pym.Parent;
|
|
private cleanups: CleanupCallback[];
|
|
|
|
constructor(config: PymControlConfig) {
|
|
const decorators = config.decorators || [];
|
|
|
|
this.pym = new pym.Parent(config.id, config.url, {
|
|
title: config.title,
|
|
id: `${config.id}_iframe`,
|
|
name: `${config.id}_iframe`,
|
|
optionalparams: "",
|
|
});
|
|
|
|
this.cleanups = decorators
|
|
.map(enhance => enhance(this.pym))
|
|
.filter(cb => cb) as CleanupCallback[];
|
|
}
|
|
|
|
public sendMessage(id: string, raw?: string) {
|
|
this.pym.sendMessage(id, raw || "");
|
|
}
|
|
|
|
public remove() {
|
|
this.cleanups.forEach(cb => cb());
|
|
this.cleanups = [];
|
|
|
|
// Remove the pym parent.
|
|
this.pym.remove();
|
|
}
|
|
}
|