2022-03-24 15:39:17 +01:00
|
|
|
import { WccDashboard } from './elements/wcc-dashboard.js';
|
2025-09-19 13:02:16 +00:00
|
|
|
import { LitElement } from 'lit';
|
|
|
|
|
import type { TTemplateFactory } from './elements/wcctools.helpers.js';
|
2025-12-28 12:51:55 +00:00
|
|
|
import type { IWccConfig, IWccSection } from './wcctools.interfaces.js';
|
2020-05-24 20:09:37 +00:00
|
|
|
|
2025-12-11 12:06:18 +00:00
|
|
|
// Export recording components and service
|
|
|
|
|
export { RecorderService, type IRecorderEvents, type IRecordingOptions } from './services/recorder.service.js';
|
|
|
|
|
export { WccRecordButton } from './elements/wcc-record-button.js';
|
|
|
|
|
export { WccRecordingPanel } from './elements/wcc-recording-panel.js';
|
|
|
|
|
|
2025-12-28 12:51:55 +00:00
|
|
|
// Export types for external use
|
|
|
|
|
export type { IWccConfig, IWccSection } from './wcctools.interfaces.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts legacy (elements, pages) format to new sections config
|
|
|
|
|
*/
|
|
|
|
|
const convertLegacyToConfig = (
|
2025-09-19 13:02:16 +00:00
|
|
|
elementsArg?: { [key: string]: LitElement },
|
|
|
|
|
pagesArg?: Record<string, TTemplateFactory>
|
2025-12-28 12:51:55 +00:00
|
|
|
): IWccConfig => {
|
|
|
|
|
const sections: IWccSection[] = [];
|
|
|
|
|
|
|
|
|
|
if (pagesArg && Object.keys(pagesArg).length > 0) {
|
|
|
|
|
sections.push({
|
|
|
|
|
name: 'Pages',
|
|
|
|
|
type: 'pages',
|
|
|
|
|
items: pagesArg,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementsArg && Object.keys(elementsArg).length > 0) {
|
|
|
|
|
sections.push({
|
|
|
|
|
name: 'Elements',
|
|
|
|
|
type: 'elements',
|
|
|
|
|
items: elementsArg,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { sections };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the argument is the new config format
|
|
|
|
|
*/
|
|
|
|
|
const isWccConfig = (arg: any): arg is IWccConfig => {
|
|
|
|
|
return arg && typeof arg === 'object' && 'sections' in arg && Array.isArray(arg.sections);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup WCC Tools dashboard
|
|
|
|
|
*
|
|
|
|
|
* New format (recommended):
|
|
|
|
|
* ```typescript
|
|
|
|
|
* setupWccTools({
|
|
|
|
|
* sections: [
|
|
|
|
|
* { name: 'Elements', type: 'elements', items: elements },
|
|
|
|
|
* { name: 'Pages', type: 'pages', items: pages },
|
|
|
|
|
* ]
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Legacy format (still supported):
|
|
|
|
|
* ```typescript
|
|
|
|
|
* setupWccTools(elements, pages);
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
const setupWccTools = (
|
|
|
|
|
configOrElements?: IWccConfig | { [key: string]: LitElement },
|
|
|
|
|
pagesArg?: Record<string, TTemplateFactory>
|
2025-09-19 13:02:16 +00:00
|
|
|
) => {
|
2025-12-28 12:51:55 +00:00
|
|
|
let config: IWccConfig;
|
|
|
|
|
|
|
|
|
|
if (isWccConfig(configOrElements)) {
|
|
|
|
|
config = configOrElements;
|
|
|
|
|
} else {
|
|
|
|
|
config = convertLegacyToConfig(configOrElements, pagesArg);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 20:09:37 +00:00
|
|
|
let hasRun = false;
|
|
|
|
|
const runWccToolsSetup = async () => {
|
|
|
|
|
if (document.readyState === 'complete' && !hasRun) {
|
|
|
|
|
hasRun = true;
|
2025-12-28 12:51:55 +00:00
|
|
|
const wccTools = new WccDashboard(config);
|
2020-05-24 20:09:37 +00:00
|
|
|
document.querySelector('body').append(wccTools);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener('readystatechange', runWccToolsSetup);
|
|
|
|
|
runWccToolsSetup();
|
|
|
|
|
};
|
2020-05-10 23:14:17 +00:00
|
|
|
|
|
|
|
|
export {
|
2020-05-24 20:09:37 +00:00
|
|
|
setupWccTools
|
2020-05-10 23:14:17 +00:00
|
|
|
};
|