]> BookStack Code Mirror - bookstack/blob - resources/js/components/index.js
Move logFailedAccess into Activity
[bookstack] / resources / js / components / index.js
1 import dropdown from "./dropdown";
2 import overlay from "./overlay";
3 import backToTop from "./back-to-top";
4 import notification from "./notification";
5 import chapterToggle from "./chapter-toggle";
6 import expandToggle from "./expand-toggle";
7 import entitySelectorPopup from "./entity-selector-popup";
8 import entitySelector from "./entity-selector";
9 import sidebar from "./sidebar";
10 import pagePicker from "./page-picker";
11 import pageComments from "./page-comments";
12 import wysiwygEditor from "./wysiwyg-editor";
13 import markdownEditor from "./markdown-editor";
14 import editorToolbox from "./editor-toolbox";
15 import imagePicker from "./image-picker";
16 import collapsible from "./collapsible";
17 import toggleSwitch from "./toggle-switch";
18 import pageDisplay from "./page-display";
19 import shelfSort from "./shelf-sort";
20 import homepageControl from "./homepage-control";
21 import headerMobileToggle from "./header-mobile-toggle";
22 import listSortControl from "./list-sort-control";
23 import triLayout from "./tri-layout";
24 import breadcrumbListing from "./breadcrumb-listing";
25 import permissionsTable from "./permissions-table";
26 import customCheckbox from "./custom-checkbox";
27 import bookSort from "./book-sort";
28 import settingAppColorPicker from "./setting-app-color-picker";
29 import settingColorPicker from "./setting-color-picker";
30 import entityPermissionsEditor from "./entity-permissions-editor";
31 import templateManager from "./template-manager";
32 import newUserPassword from "./new-user-password";
33 import detailsHighlighter from "./details-highlighter";
34 import codeHighlighter from "./code-highlighter";
35
36 const componentMapping = {
37     'dropdown': dropdown,
38     'overlay': overlay,
39     'back-to-top': backToTop,
40     'notification': notification,
41     'chapter-toggle': chapterToggle,
42     'expand-toggle': expandToggle,
43     'entity-selector-popup': entitySelectorPopup,
44     'entity-selector': entitySelector,
45     'sidebar': sidebar,
46     'page-picker': pagePicker,
47     'page-comments': pageComments,
48     'wysiwyg-editor': wysiwygEditor,
49     'markdown-editor': markdownEditor,
50     'editor-toolbox': editorToolbox,
51     'image-picker': imagePicker,
52     'collapsible': collapsible,
53     'toggle-switch': toggleSwitch,
54     'page-display': pageDisplay,
55     'shelf-sort': shelfSort,
56     'homepage-control': homepageControl,
57     'header-mobile-toggle': headerMobileToggle,
58     'list-sort-control': listSortControl,
59     'tri-layout': triLayout,
60     'breadcrumb-listing': breadcrumbListing,
61     'permissions-table': permissionsTable,
62     'custom-checkbox': customCheckbox,
63     'book-sort': bookSort,
64     'setting-app-color-picker': settingAppColorPicker,
65     'setting-color-picker': settingColorPicker,
66     'entity-permissions-editor': entityPermissionsEditor,
67     'template-manager': templateManager,
68     'new-user-password': newUserPassword,
69     'details-highlighter': detailsHighlighter,
70     'code-highlighter': codeHighlighter,
71 };
72
73 window.components = {};
74
75 const componentNames = Object.keys(componentMapping);
76
77 /**
78  * Initialize components of the given name within the given element.
79  * @param {String} componentName
80  * @param {HTMLElement|Document} parentElement
81  */
82 function initComponent(componentName, parentElement) {
83     let elems = parentElement.querySelectorAll(`[${componentName}]`);
84     if (elems.length === 0) return;
85
86     let component = componentMapping[componentName];
87     if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
88     for (let j = 0, jLen = elems.length; j < jLen; j++) {
89         let instance = new component(elems[j]);
90         if (typeof elems[j].components === 'undefined') elems[j].components = {};
91         elems[j].components[componentName] = instance;
92         window.components[componentName].push(instance);
93     }
94 }
95
96 /**
97  * Initialize all components found within the given element.
98  * @param parentElement
99  */
100 function initAll(parentElement) {
101     if (typeof parentElement === 'undefined') parentElement = document;
102     for (let i = 0, len = componentNames.length; i < len; i++) {
103         initComponent(componentNames[i], parentElement);
104     }
105 }
106
107 window.components.init = initAll;
108
109 export default initAll;