primevue-mirror/layouts/AppDocumentation.vue

159 lines
5.5 KiB
Vue
Raw Normal View History

2022-09-09 14:35:31 +00:00
<script lang="jsx">
import LiveEditor from '@/pages/liveeditor/LiveEditor';
2022-12-22 08:40:59 +00:00
import { data, services } from '@/pages/liveeditor/LiveEditorData';
import EventBus from './AppEventBus';
2021-03-17 11:29:01 +00:00
export default {
name: 'appdoc',
props: {
name: null,
sources: null,
service: null,
data: null,
dependencies: null,
2021-03-25 09:04:37 +00:00
extPages: null,
2021-03-31 12:28:03 +00:00
extFiles: null,
2021-04-05 09:29:28 +00:00
component: null,
2022-12-22 08:40:59 +00:00
github: {
type: String,
2022-12-22 12:49:31 +00:00
default: 'index.vue'
2022-12-22 08:40:59 +00:00
}
2021-04-05 09:29:28 +00:00
},
2021-04-15 14:53:33 +00:00
viewGithubListener: null,
2021-04-05 09:29:28 +00:00
mounted() {
2021-04-15 14:53:33 +00:00
this.viewGithubListener = () => {
2022-12-22 12:49:31 +00:00
window.open('https://github.com/primefaces/primevue/blob/master/pages/' + this.name.toLowerCase().replaceAll('demo', '/') + this.github, '_blank');
2021-04-15 14:53:33 +00:00
};
2022-12-22 13:20:07 +00:00
2021-04-15 14:53:33 +00:00
EventBus.on('view-github', this.viewGithubListener);
2021-04-05 09:29:28 +00:00
},
beforeUnmount() {
2021-04-15 14:53:33 +00:00
EventBus.off('view-github', this.viewGithubListener);
2021-03-17 11:29:01 +00:00
},
methods: {
renderPanels() {
let tabs = [];
if (this.$slots.default) {
tabs.push(<TabPanel header="Documentation">{this.$slots.default()}</TabPanel>);
}
2021-04-05 09:29:28 +00:00
this.renderSource('options-api', tabs);
this.renderSource('composition-api', tabs);
2021-10-11 13:48:01 +00:00
this.renderSource('browser-source', tabs);
2022-06-14 13:25:50 +00:00
this.renderSource('demo1', tabs);
this.renderSource('demo2', tabs);
2021-03-17 11:29:01 +00:00
if (this.service) {
2021-03-23 10:47:50 +00:00
let serviceArr = [];
2022-09-14 14:26:41 +00:00
this.service.forEach((el) => {
serviceArr.push(el.split(','));
});
2021-03-17 11:29:01 +00:00
/* eslint-disable */
2021-03-23 10:47:50 +00:00
serviceArr.forEach((el, i) => {
tabs.push(
2021-04-05 09:29:28 +00:00
<TabPanel key={el} header={`${el}.js`}>
2022-09-14 14:26:41 +00:00
<pre v-code="script">
<code>{services[el]}</code>
</pre>
2021-03-23 10:47:50 +00:00
</TabPanel>
);
2022-09-14 14:26:41 +00:00
});
2021-03-17 11:29:01 +00:00
}
if (this.data) {
let dataArr = [];
2022-09-14 14:26:41 +00:00
this.data.forEach((el) => {
dataArr.push(el.split(','));
});
2022-07-18 13:17:40 +00:00
2021-03-17 11:29:01 +00:00
dataArr.forEach((el, i) => {
tabs.push(
<TabPanel key={`${el}_i`} header={`${el}.json`}>
2022-09-14 14:26:41 +00:00
<pre v-code="script" style={{ maxHeight: '500px' }}>
<code>{data[el]}</code>
</pre>
2021-03-17 11:29:01 +00:00
</TabPanel>
2022-09-14 14:26:41 +00:00
);
2021-03-17 11:29:01 +00:00
});
}
return tabs;
2021-04-05 09:29:28 +00:00
},
2021-10-11 13:48:01 +00:00
renderContent(source) {
if (source.tabName === 'Browser Source') {
const _imports = source.imports ? source.imports.replaceAll('<\\/script>', '<\/script>') : '';
2021-10-19 07:04:20 +00:00
return `
<!DOCTYPE html>
2021-10-11 13:48:01 +00:00
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!-- PrimeVue -->
<link href="https://unpkg.com/primevue@^3/resources/themes/saga-blue/theme.css" rel="stylesheet" />
<link href="https://unpkg.com/primevue@^3/resources/primevue.min.css" rel="stylesheet" />
2022-01-13 11:03:59 +00:00
<link href="https://unpkg.com/primeflex@^3/primeflex.min.css" rel="stylesheet" />
2021-10-11 13:48:01 +00:00
<link href="https://unpkg.com/primeicons/primeicons.css" rel="stylesheet" />
<!-- Dependencies -->
<script src="https://unpkg.com/vue@next"><\/script>
2021-10-26 08:41:57 +00:00
<script src="https://unpkg.com/primevue@^3/core/core.min.js"><\/script>
2021-10-11 13:48:01 +00:00
<!-- Demo -->
${_imports}
2021-10-11 14:06:13 +00:00
<link href="./index.css" rel="stylesheet" />
2021-10-11 13:48:01 +00:00
</head>
<body>
${source.content.replace('<\\/script>', '<\/script>')}
</body>
</html>
2022-09-14 14:26:41 +00:00
`;
2021-10-11 13:48:01 +00:00
}
return source.content.replace('<\\/script>', '<\/script>');
},
2021-04-05 09:29:28 +00:00
renderSource(sourceType, tabs) {
if (this.sources && this.sources[sourceType]) {
2022-07-18 13:17:40 +00:00
let extFiles = this.extFiles ? this.extFiles[sourceType] || this.extFiles : null;
2022-09-14 14:26:41 +00:00
extFiles =
extFiles &&
Object.entries(extFiles).map(([key, value], i) => {
if (key === 'index.css' || !value.content) {
return null;
}
2022-07-18 13:17:40 +00:00
2022-09-14 14:26:41 +00:00
return (
<pre v-code>
<code>
{`\n/* ${key.replace('src/components/', '')} */\n`}
{this.renderContent(value)}
</code>
</pre>
);
});
2022-07-18 13:17:40 +00:00
2021-04-05 09:29:28 +00:00
tabs.push(
<TabPanel key={sourceType} header={this.sources[sourceType].tabName}>
2022-09-14 14:26:41 +00:00
<pre v-code>
<code>{this.renderContent(this.sources[sourceType])}</code>
</pre>
2022-07-18 13:17:40 +00:00
{extFiles}
2021-04-05 09:29:28 +00:00
</TabPanel>
);
}
2021-03-17 11:29:01 +00:00
}
},
render() {
return (
2021-04-05 09:29:28 +00:00
<div class="content-section documentation" id="app-doc">
<LiveEditor name={this.name} sources={this.sources} service={this.service} data={this.data} dependencies={this.dependencies} extPages={this.extPages} extFiles={this.extFiles} component={this.component} />
2022-09-14 14:26:41 +00:00
<TabView>{this.renderPanels()}</TabView>
2021-03-17 11:29:01 +00:00
</div>
);
}
2022-09-14 14:26:41 +00:00
};
2021-03-17 11:29:01 +00:00
</script>