No Description

app.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {createAppPageComponent} from './components/app-page';
  2. function init() {
  3. const components = loadComponents();
  4. const categories = loadCategories(components);
  5. const themes = loadThemes();
  6. const patterns = loadPatterns();
  7. window.components = components;
  8. window.categories = categories;
  9. window.themes = themes;
  10. window.patterns = patterns;
  11. const app = new Vue(createAppPageComponent({
  12. components,
  13. categories
  14. }));
  15. };
  16. function loadCategories(components) {
  17. const set = new Set();
  18. components.forEach(component => {
  19. set.add(component.category);
  20. });
  21. return [...set.values()].map(value => {
  22. return {
  23. name: value,
  24. hash: value.toLowerCase().replace(/ /g, '_')
  25. };
  26. });
  27. }
  28. function loadComponents() {
  29. return JSON.parse(document.querySelector('#data').getAttribute('data-components')).map(component => {
  30. component = component.annotation;
  31. component.id = component.name.toLowerCase().replace(/ /g, '_');
  32. return component;
  33. });
  34. }
  35. function loadThemes() {
  36. const themes = JSON.parse(document.querySelector('#data').getAttribute('data-themes')).map(theme => {
  37. return theme;
  38. }).filter(theme => {
  39. return theme !== 'onsen-css-components';
  40. });
  41. // デフォルトのテーマを先頭に追加
  42. themes.unshift('onsen-css-components');
  43. return themes;
  44. }
  45. function loadPatterns() {
  46. return JSON.parse(document.querySelector('#data').getAttribute('data-patterns')).map(pattern => {
  47. pattern.id = pattern.name.toLowerCase().replace(/ +/g, '_');
  48. return pattern;
  49. });
  50. }
  51. window.onload = init;