UNPKG

@curvenote/cli-plugin

Version:
52 lines (51 loc) 1.86 kB
import { u } from 'unist-builder'; import { makePlaceholder, validateStringOptions } from '../../utils.js'; export const anyBundle = { name: 'any:bundle', doc: 'Embed a bundled AnyWidget component with data in the body', arg: { type: String, required: true, doc: 'A URL to the AnyWidget component bundle', }, options: { class: { type: String, required: false, doc: 'Tailwind classes to apply to the container element', }, styles: { type: String, required: false, doc: 'URL to the CSS file', }, }, body: { doc: 'JSON object with props to pass down to the component', type: String, required: true, }, validate(data, vfile) { var _a, _b; // TODO: validate the URL for the esm validateStringOptions(vfile, 'arg', data.arg); validateStringOptions(vfile, 'class', (_a = data.options) === null || _a === void 0 ? void 0 : _a.class); validateStringOptions(vfile, 'styles', (_b = data.options) === null || _b === void 0 ? void 0 : _b.styles); validateStringOptions(vfile, 'body', data.body); return data; }, run(data, _vfile, _opts) { var _a, _b, _c, _d; const body = data.body; const block = u('block', { kind: 'any:bundle', data: { import: data.arg, class: (_b = (_a = data.options) === null || _a === void 0 ? void 0 : _a.class) !== null && _b !== void 0 ? _b : '', styles: (_d = (_c = data.options) === null || _c === void 0 ? void 0 : _c.styles) !== null && _d !== void 0 ? _d : '', json: JSON.parse(body), }, }, makePlaceholder(data, data.arg)); return [block]; }, };