docus 1.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -24
- package/dist/index.cjs +549 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.mjs +523 -0
- package/dist/runtime/app/components/DocusContent.vue +215 -0
- package/dist/runtime/app/components/DocusContent.vue.d.ts +25 -0
- package/dist/runtime/app/components/Error.vue +19 -0
- package/dist/runtime/app/components/Error.vue.d.ts +9 -0
- package/dist/runtime/app/components/Markdown.vue +56 -0
- package/dist/runtime/app/components/Markdown.vue.d.ts +25 -0
- package/dist/runtime/app/components/Page.vue +29 -0
- package/dist/runtime/app/components/Page.vue.d.ts +2 -0
- package/dist/runtime/app/components/Props.vue +130 -0
- package/dist/runtime/app/components/Props.vue.d.ts +80 -0
- package/dist/runtime/app/components/prose/ProseA.vue +41 -0
- package/dist/runtime/app/components/prose/ProseA.vue.d.ts +23 -0
- package/dist/runtime/app/components/prose/ProseBlockquote.vue +5 -0
- package/dist/runtime/app/components/prose/ProseCode.vue +5 -0
- package/dist/runtime/app/components/prose/ProseCodeInline.vue +5 -0
- package/dist/runtime/app/components/prose/ProseEm.vue +5 -0
- package/dist/runtime/app/components/prose/ProseH1.vue +3 -0
- package/dist/runtime/app/components/prose/ProseH2.vue +3 -0
- package/dist/runtime/app/components/prose/ProseH3.vue +3 -0
- package/dist/runtime/app/components/prose/ProseH4.vue +3 -0
- package/dist/runtime/app/components/prose/ProseH5.vue +3 -0
- package/dist/runtime/app/components/prose/ProseH6.vue +3 -0
- package/dist/runtime/app/components/prose/ProseHr.vue +3 -0
- package/dist/runtime/app/components/prose/ProseImg.vue +32 -0
- package/dist/runtime/app/components/prose/ProseImg.vue.d.ts +21 -0
- package/dist/runtime/app/components/prose/ProseLi.vue +3 -0
- package/dist/runtime/app/components/prose/ProseOl.vue +5 -0
- package/dist/runtime/app/components/prose/ProseParagraph.vue +3 -0
- package/dist/runtime/app/components/prose/ProseStrong.vue +5 -0
- package/dist/runtime/app/components/prose/ProseTable.vue +5 -0
- package/dist/runtime/app/components/prose/ProseTbody.vue +5 -0
- package/dist/runtime/app/components/prose/ProseTd.vue +5 -0
- package/dist/runtime/app/components/prose/ProseTh.vue +5 -0
- package/dist/runtime/app/components/prose/ProseThead.vue +5 -0
- package/dist/runtime/app/components/prose/ProseTr.vue +5 -0
- package/dist/runtime/app/components/prose/ProseUl.vue +5 -0
- package/dist/runtime/app/composables/helpers.d.ts +4 -0
- package/dist/runtime/app/composables/helpers.js +66 -0
- package/dist/runtime/app/composables/helpers.mjs +40 -0
- package/dist/runtime/app/composables/index.d.ts +90 -0
- package/dist/runtime/app/composables/index.js +108 -0
- package/dist/runtime/app/composables/index.mjs +63 -0
- package/dist/runtime/app/composables/navigation.d.ts +37 -0
- package/dist/runtime/app/composables/navigation.js +227 -0
- package/dist/runtime/app/composables/navigation.mjs +148 -0
- package/dist/runtime/app/composables/store.d.ts +7 -0
- package/dist/runtime/app/composables/store.js +52 -0
- package/dist/runtime/app/composables/store.mjs +35 -0
- package/dist/runtime/app/composables/style.d.ts +11 -0
- package/dist/runtime/app/composables/style.js +117 -0
- package/dist/runtime/app/composables/style.mjs +71 -0
- package/dist/runtime/app/composables/theme-colors.d.ts +30 -0
- package/dist/runtime/app/composables/theme-colors.js +80 -0
- package/dist/runtime/app/composables/theme-colors.mjs +48 -0
- package/dist/runtime/app/composables/websocket.d.ts +3 -0
- package/dist/runtime/app/composables/websocket.js +79 -0
- package/dist/runtime/app/composables/websocket.mjs +63 -0
- package/dist/runtime/app/layouts/default.vue +5 -0
- package/dist/runtime/app/layouts/error.vue +33 -0
- package/dist/runtime/app/layouts/error.vue.d.ts +21 -0
- package/dist/runtime/app/pages/_.vue +222 -0
- package/dist/runtime/app/pages/_.vue.d.ts +2 -0
- package/dist/runtime/context.d.ts +1 -0
- package/dist/runtime/context.js +17 -0
- package/dist/runtime/context.mjs +5 -0
- package/dist/runtime/database/Query.d.ts +18 -0
- package/dist/runtime/database/Query.js +68 -0
- package/dist/runtime/database/Query.mjs +49 -0
- package/dist/runtime/database/index.d.ts +4 -0
- package/dist/runtime/database/index.js +45 -0
- package/dist/runtime/database/index.mjs +25 -0
- package/dist/runtime/database/providers/local/Query.d.ts +14 -0
- package/dist/runtime/database/providers/local/Query.js +85 -0
- package/dist/runtime/database/providers/local/Query.mjs +60 -0
- package/dist/runtime/database/providers/local/index.d.ts +3 -0
- package/dist/runtime/database/providers/local/index.js +63 -0
- package/dist/runtime/database/providers/local/index.mjs +39 -0
- package/dist/runtime/database/providers/local/operations.d.ts +2 -0
- package/dist/runtime/database/providers/local/operations.js +83 -0
- package/dist/runtime/database/providers/local/operations.mjs +53 -0
- package/dist/runtime/database/providers/local/utils.d.ts +8 -0
- package/dist/runtime/database/providers/local/utils.js +28 -0
- package/dist/runtime/database/providers/local/utils.mjs +17 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +44 -0
- package/dist/runtime/index.mjs +3 -0
- package/dist/runtime/navigation.d.ts +4 -0
- package/dist/runtime/navigation.js +176 -0
- package/dist/runtime/navigation.mjs +137 -0
- package/dist/runtime/server/api/get.d.ts +10 -0
- package/dist/runtime/server/api/get.js +24 -0
- package/dist/runtime/server/api/get.mjs +13 -0
- package/dist/runtime/server/api/list.d.ts +9 -0
- package/dist/runtime/server/api/list.js +34 -0
- package/dist/runtime/server/api/list.mjs +18 -0
- package/dist/runtime/server/api/navigation.d.ts +7 -0
- package/dist/runtime/server/api/navigation.js +20 -0
- package/dist/runtime/server/api/navigation.mjs +10 -0
- package/dist/runtime/server/api/preview.d.ts +3 -0
- package/dist/runtime/server/api/preview.js +54 -0
- package/dist/runtime/server/api/preview.mjs +31 -0
- package/dist/runtime/server/api/reload.d.ts +6 -0
- package/dist/runtime/server/api/reload.js +27 -0
- package/dist/runtime/server/api/reload.mjs +11 -0
- package/dist/runtime/server/api/search.d.ts +6 -0
- package/dist/runtime/server/api/search.js +27 -0
- package/dist/runtime/server/api/search.mjs +13 -0
- package/dist/runtime/server/content.d.ts +46 -0
- package/dist/runtime/server/content.js +175 -0
- package/dist/runtime/server/content.mjs +114 -0
- package/dist/runtime/server/socket.d.ts +9 -0
- package/dist/runtime/server/socket.js +33 -0
- package/dist/runtime/server/socket.mjs +20 -0
- package/dist/runtime/server/utils/cache.d.ts +19 -0
- package/dist/runtime/server/utils/cache.js +110 -0
- package/dist/runtime/server/utils/cache.mjs +75 -0
- package/dist/runtime/server/utils/index.d.ts +4 -0
- package/dist/runtime/server/utils/index.js +18 -0
- package/dist/runtime/server/utils/index.mjs +8 -0
- package/dist/runtime/transformers/index.d.ts +1 -0
- package/dist/runtime/transformers/index.js +26 -0
- package/dist/runtime/transformers/index.mjs +11 -0
- package/dist/runtime/transformers/json.d.ts +3 -0
- package/dist/runtime/transformers/json.js +15 -0
- package/dist/runtime/transformers/json.mjs +5 -0
- package/dist/runtime/transformers/markdown/index.d.ts +8 -0
- package/dist/runtime/transformers/markdown/index.js +25 -0
- package/dist/runtime/transformers/markdown/index.mjs +16 -0
- package/dist/runtime/transformers/utils/index.d.ts +1 -0
- package/dist/runtime/transformers/utils/index.js +18 -0
- package/dist/runtime/transformers/utils/index.mjs +1 -0
- package/dist/runtime/transformers/utils/path.d.ts +26 -0
- package/dist/runtime/transformers/utils/path.js +88 -0
- package/dist/runtime/transformers/utils/path.mjs +56 -0
- package/dist/runtime/utils/index.d.ts +1 -0
- package/dist/runtime/utils/index.js +18 -0
- package/dist/runtime/utils/index.mjs +1 -0
- package/dist/runtime/utils/log.d.ts +1 -0
- package/dist/runtime/utils/log.js +14 -0
- package/dist/runtime/utils/log.mjs +2 -0
- package/dist/runtime/utils/object.d.ts +9 -0
- package/dist/runtime/utils/object.js +22 -0
- package/dist/runtime/utils/object.mjs +4 -0
- package/dist/templates/content.mjs +50 -0
- package/dist/templates/docus.mjs +13 -0
- package/dist/templates/hot.mjs +16 -0
- package/dist/templates/i18n.mjs +23 -0
- package/dist/templates/options.mjs +46 -0
- package/package.json +78 -58
- package/shims.d.ts +24 -0
- package/types.d.ts +397 -0
- package/dist/create-docus/create-docus.js +0 -7
- package/dist/create-docus/index.js +0 -122
- package/dist/helpers.js +0 -154
- package/dist/index.js +0 -10
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDocusNavigationState = exports.useDocusNavigation = exports.useDocusCurrentPath = exports.useDocusCurrentNav = exports.createDocusNavigation = void 0;
|
|
7
|
+
|
|
8
|
+
var _ufo = require("ufo");
|
|
9
|
+
|
|
10
|
+
var _vue = _interopRequireDefault(require("vue"));
|
|
11
|
+
|
|
12
|
+
var _scule = require("scule");
|
|
13
|
+
|
|
14
|
+
var _ = require(".");
|
|
15
|
+
|
|
16
|
+
var _app = require("#app");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
let _get;
|
|
21
|
+
|
|
22
|
+
let _fetchNavigation;
|
|
23
|
+
|
|
24
|
+
let _filterLinks;
|
|
25
|
+
|
|
26
|
+
let _isLinkActive;
|
|
27
|
+
|
|
28
|
+
let _getPageTemplate;
|
|
29
|
+
|
|
30
|
+
let _getPreviousAndNextLink;
|
|
31
|
+
|
|
32
|
+
let _updateCurrentNav;
|
|
33
|
+
|
|
34
|
+
let _refresh;
|
|
35
|
+
|
|
36
|
+
const createDocusNavigation = (context, config, content) => {
|
|
37
|
+
const _contentLocalePath = context.$contentLocalePath;
|
|
38
|
+
const {
|
|
39
|
+
route
|
|
40
|
+
} = context;
|
|
41
|
+
|
|
42
|
+
const _route = (0, _app.unref)(route);
|
|
43
|
+
|
|
44
|
+
const docusNavigation = (0, _app.useState)(_.StateTypes.Navigation, () => ({}));
|
|
45
|
+
const docusCurrentPath = (0, _app.useState)(_.StateTypes.CurrentPath, () => `/${_route.params.pathMatch}`);
|
|
46
|
+
|
|
47
|
+
_fetchNavigation = async locale => {
|
|
48
|
+
const __locale = locale || context.i18n.locale;
|
|
49
|
+
|
|
50
|
+
const data = await content.fetch("navigation/" + __locale);
|
|
51
|
+
docusNavigation.value[__locale] = data;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
_get = ({
|
|
55
|
+
depth,
|
|
56
|
+
locale = context.i18n.locale,
|
|
57
|
+
from,
|
|
58
|
+
all
|
|
59
|
+
} = {}) => {
|
|
60
|
+
const nav = docusNavigation.value[locale] || [];
|
|
61
|
+
let items = nav;
|
|
62
|
+
let match;
|
|
63
|
+
let exclusiveContent;
|
|
64
|
+
let parent;
|
|
65
|
+
|
|
66
|
+
if (from) {
|
|
67
|
+
let lastMatch;
|
|
68
|
+
const paths = from.split("/");
|
|
69
|
+
items = paths.reduce((links, path, index) => {
|
|
70
|
+
if (!path) return links;
|
|
71
|
+
|
|
72
|
+
if (match && match.page) {
|
|
73
|
+
lastMatch = match;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
match = links.find(item => item.to.split("/")[index] === path);
|
|
77
|
+
|
|
78
|
+
if (match) {
|
|
79
|
+
if (match && match.exclusive) {
|
|
80
|
+
parent = lastMatch || parent;
|
|
81
|
+
exclusiveContent = match;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return match.children;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return links;
|
|
88
|
+
}, items);
|
|
89
|
+
|
|
90
|
+
if (exclusiveContent) {
|
|
91
|
+
items = exclusiveContent.children;
|
|
92
|
+
} else {
|
|
93
|
+
items = nav;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
title: exclusiveContent && exclusiveContent.title,
|
|
99
|
+
to: exclusiveContent && exclusiveContent.to,
|
|
100
|
+
parent,
|
|
101
|
+
links: all ? items : _filterLinks(items, depth || 1, 1)
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
_filterLinks = (nodes, maxDepth, currentDepth) => {
|
|
106
|
+
return nodes.filter(node => {
|
|
107
|
+
if (node.hidden) return false;
|
|
108
|
+
if (node.draft === true) return false;
|
|
109
|
+
if (currentDepth && maxDepth > currentDepth) return false;
|
|
110
|
+
if (node.nested === false) node.children = [];
|
|
111
|
+
node.children = node.children && node.children.length > 0 ? _filterLinks(node.children, maxDepth, currentDepth + 1) : [];
|
|
112
|
+
return node;
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
_isLinkActive = to => {
|
|
117
|
+
return (0, _ufo.withTrailingSlash)(docusCurrentPath.value) === (0, _ufo.withTrailingSlash)(_contentLocalePath(to));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
_getPageTemplate = page => {
|
|
121
|
+
let template = typeof page.template === "string" ? page.template : page.template?.self;
|
|
122
|
+
|
|
123
|
+
if (!template) {
|
|
124
|
+
const slugs = page.to.split("/").filter(Boolean).slice(0, -1);
|
|
125
|
+
let {
|
|
126
|
+
links
|
|
127
|
+
} = docusCurrentNav.value || {};
|
|
128
|
+
slugs.forEach((_slug, index) => {
|
|
129
|
+
const to = "/" + slugs.slice(0, index + 1).join("/");
|
|
130
|
+
const link = links.find(link2 => link2.to === to);
|
|
131
|
+
|
|
132
|
+
if (link?.template) {
|
|
133
|
+
template = link.template || template;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!link?.children) return;
|
|
137
|
+
links = link.children;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!template) template = config.value?.template || "Page";
|
|
142
|
+
template = (0, _scule.pascalCase)(template);
|
|
143
|
+
|
|
144
|
+
if (!_vue.default.component(template)) {
|
|
145
|
+
console.error(`Template ${template} does not exists, fallback to Page template.`);
|
|
146
|
+
template = "Page";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return template;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
_getPreviousAndNextLink = page => {
|
|
153
|
+
return content.search({
|
|
154
|
+
deep: true
|
|
155
|
+
}).where({
|
|
156
|
+
language: context.i18n.locale,
|
|
157
|
+
parent: page.parent,
|
|
158
|
+
page: {
|
|
159
|
+
$ne: false
|
|
160
|
+
},
|
|
161
|
+
hidden: {
|
|
162
|
+
$ne: true
|
|
163
|
+
},
|
|
164
|
+
redirect: {
|
|
165
|
+
$type: "undefined"
|
|
166
|
+
}
|
|
167
|
+
}).only(["title", "slug", "to"]).sortBy("position", "asc").surround(page.to, {
|
|
168
|
+
before: 1,
|
|
169
|
+
after: 1
|
|
170
|
+
}).fetch();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
_updateCurrentNav = () => {
|
|
174
|
+
docusCurrentNav.value = _get({
|
|
175
|
+
from: docusCurrentPath.value
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
_refresh = async locale => {
|
|
180
|
+
await _fetchNavigation(locale);
|
|
181
|
+
|
|
182
|
+
_updateCurrentNav();
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const docusCurrentNav = (0, _app.useState)(_.StateTypes.CurrentNav, () => {
|
|
186
|
+
return _get({
|
|
187
|
+
from: `/${_route.params.pathMatch}`
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (process.client) {
|
|
192
|
+
window.onNuxtReady(() => {
|
|
193
|
+
window.$nuxt.$on("docus:content:preview", () => _refresh(context.i18n.locale));
|
|
194
|
+
window.$nuxt.$on("content:update", () => _refresh(context.i18n.locale));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
exports.createDocusNavigation = createDocusNavigation;
|
|
200
|
+
|
|
201
|
+
const useDocusNavigation = () => {
|
|
202
|
+
return {
|
|
203
|
+
state: useDocusNavigationState(),
|
|
204
|
+
currentNav: useDocusCurrentNav(),
|
|
205
|
+
currentPath: useDocusCurrentPath(),
|
|
206
|
+
getPageTemplate: _getPageTemplate,
|
|
207
|
+
fetchNavigation: _fetchNavigation,
|
|
208
|
+
isLinkActive: _isLinkActive,
|
|
209
|
+
updateCurrentNav: _updateCurrentNav,
|
|
210
|
+
getPreviousAndNextLink: _getPreviousAndNextLink,
|
|
211
|
+
get: _get
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
exports.useDocusNavigation = useDocusNavigation;
|
|
216
|
+
|
|
217
|
+
const useDocusNavigationState = () => (0, _app.useState)(_.StateTypes.Navigation);
|
|
218
|
+
|
|
219
|
+
exports.useDocusNavigationState = useDocusNavigationState;
|
|
220
|
+
|
|
221
|
+
const useDocusCurrentNav = () => (0, _app.useState)(_.StateTypes.CurrentNav);
|
|
222
|
+
|
|
223
|
+
exports.useDocusCurrentNav = useDocusCurrentNav;
|
|
224
|
+
|
|
225
|
+
const useDocusCurrentPath = () => (0, _app.useState)(_.StateTypes.CurrentPath);
|
|
226
|
+
|
|
227
|
+
exports.useDocusCurrentPath = useDocusCurrentPath;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { withTrailingSlash } from "ufo";
|
|
2
|
+
import Vue from "vue";
|
|
3
|
+
import { pascalCase } from "scule";
|
|
4
|
+
import { StateTypes } from "./index.mjs";
|
|
5
|
+
import { unref, useState } from "#app";
|
|
6
|
+
let _get;
|
|
7
|
+
let _fetchNavigation;
|
|
8
|
+
let _filterLinks;
|
|
9
|
+
let _isLinkActive;
|
|
10
|
+
let _getPageTemplate;
|
|
11
|
+
let _getPreviousAndNextLink;
|
|
12
|
+
let _updateCurrentNav;
|
|
13
|
+
let _refresh;
|
|
14
|
+
export const createDocusNavigation = (context, config, content) => {
|
|
15
|
+
const _contentLocalePath = context.$contentLocalePath;
|
|
16
|
+
const { route } = context;
|
|
17
|
+
const _route = unref(route);
|
|
18
|
+
const docusNavigation = useState(StateTypes.Navigation, () => ({}));
|
|
19
|
+
const docusCurrentPath = useState(StateTypes.CurrentPath, () => `/${_route.params.pathMatch}`);
|
|
20
|
+
_fetchNavigation = async (locale) => {
|
|
21
|
+
const __locale = locale || context.i18n.locale;
|
|
22
|
+
const data = await content.fetch("navigation/" + __locale);
|
|
23
|
+
docusNavigation.value[__locale] = data;
|
|
24
|
+
};
|
|
25
|
+
_get = ({ depth, locale = context.i18n.locale, from, all } = {}) => {
|
|
26
|
+
const nav = docusNavigation.value[locale] || [];
|
|
27
|
+
let items = nav;
|
|
28
|
+
let match;
|
|
29
|
+
let exclusiveContent;
|
|
30
|
+
let parent;
|
|
31
|
+
if (from) {
|
|
32
|
+
let lastMatch;
|
|
33
|
+
const paths = from.split("/");
|
|
34
|
+
items = paths.reduce((links, path, index) => {
|
|
35
|
+
if (!path)
|
|
36
|
+
return links;
|
|
37
|
+
if (match && match.page) {
|
|
38
|
+
lastMatch = match;
|
|
39
|
+
}
|
|
40
|
+
match = links.find((item) => item.to.split("/")[index] === path);
|
|
41
|
+
if (match) {
|
|
42
|
+
if (match && match.exclusive) {
|
|
43
|
+
parent = lastMatch || parent;
|
|
44
|
+
exclusiveContent = match;
|
|
45
|
+
}
|
|
46
|
+
return match.children;
|
|
47
|
+
}
|
|
48
|
+
return links;
|
|
49
|
+
}, items);
|
|
50
|
+
if (exclusiveContent) {
|
|
51
|
+
items = exclusiveContent.children;
|
|
52
|
+
} else {
|
|
53
|
+
items = nav;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
title: exclusiveContent && exclusiveContent.title,
|
|
58
|
+
to: exclusiveContent && exclusiveContent.to,
|
|
59
|
+
parent,
|
|
60
|
+
links: all ? items : _filterLinks(items, depth || 1, 1)
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
_filterLinks = (nodes, maxDepth, currentDepth) => {
|
|
64
|
+
return nodes.filter((node) => {
|
|
65
|
+
if (node.hidden)
|
|
66
|
+
return false;
|
|
67
|
+
if (node.draft === true)
|
|
68
|
+
return false;
|
|
69
|
+
if (currentDepth && maxDepth > currentDepth)
|
|
70
|
+
return false;
|
|
71
|
+
if (node.nested === false)
|
|
72
|
+
node.children = [];
|
|
73
|
+
node.children = node.children && node.children.length > 0 ? _filterLinks(node.children, maxDepth, currentDepth + 1) : [];
|
|
74
|
+
return node;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
_isLinkActive = (to) => {
|
|
78
|
+
return withTrailingSlash(docusCurrentPath.value) === withTrailingSlash(_contentLocalePath(to));
|
|
79
|
+
};
|
|
80
|
+
_getPageTemplate = (page) => {
|
|
81
|
+
let template = typeof page.template === "string" ? page.template : page.template?.self;
|
|
82
|
+
if (!template) {
|
|
83
|
+
const slugs = page.to.split("/").filter(Boolean).slice(0, -1);
|
|
84
|
+
let { links } = docusCurrentNav.value || {};
|
|
85
|
+
slugs.forEach((_slug, index) => {
|
|
86
|
+
const to = "/" + slugs.slice(0, index + 1).join("/");
|
|
87
|
+
const link = links.find((link2) => link2.to === to);
|
|
88
|
+
if (link?.template) {
|
|
89
|
+
template = link.template || template;
|
|
90
|
+
}
|
|
91
|
+
if (!link?.children)
|
|
92
|
+
return;
|
|
93
|
+
links = link.children;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (!template)
|
|
97
|
+
template = config.value?.template || "Page";
|
|
98
|
+
template = pascalCase(template);
|
|
99
|
+
if (!Vue.component(template)) {
|
|
100
|
+
console.error(`Template ${template} does not exists, fallback to Page template.`);
|
|
101
|
+
template = "Page";
|
|
102
|
+
}
|
|
103
|
+
return template;
|
|
104
|
+
};
|
|
105
|
+
_getPreviousAndNextLink = (page) => {
|
|
106
|
+
return content.search({ deep: true }).where({
|
|
107
|
+
language: context.i18n.locale,
|
|
108
|
+
parent: page.parent,
|
|
109
|
+
page: { $ne: false },
|
|
110
|
+
hidden: { $ne: true },
|
|
111
|
+
redirect: { $type: "undefined" }
|
|
112
|
+
}).only(["title", "slug", "to"]).sortBy("position", "asc").surround(page.to, { before: 1, after: 1 }).fetch();
|
|
113
|
+
};
|
|
114
|
+
_updateCurrentNav = () => {
|
|
115
|
+
docusCurrentNav.value = _get({
|
|
116
|
+
from: docusCurrentPath.value
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
_refresh = async (locale) => {
|
|
120
|
+
await _fetchNavigation(locale);
|
|
121
|
+
_updateCurrentNav();
|
|
122
|
+
};
|
|
123
|
+
const docusCurrentNav = useState(StateTypes.CurrentNav, () => {
|
|
124
|
+
return _get({ from: `/${_route.params.pathMatch}` });
|
|
125
|
+
});
|
|
126
|
+
if (process.client) {
|
|
127
|
+
window.onNuxtReady(() => {
|
|
128
|
+
window.$nuxt.$on("docus:content:preview", () => _refresh(context.i18n.locale));
|
|
129
|
+
window.$nuxt.$on("content:update", () => _refresh(context.i18n.locale));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
export const useDocusNavigation = () => {
|
|
134
|
+
return {
|
|
135
|
+
state: useDocusNavigationState(),
|
|
136
|
+
currentNav: useDocusCurrentNav(),
|
|
137
|
+
currentPath: useDocusCurrentPath(),
|
|
138
|
+
getPageTemplate: _getPageTemplate,
|
|
139
|
+
fetchNavigation: _fetchNavigation,
|
|
140
|
+
isLinkActive: _isLinkActive,
|
|
141
|
+
updateCurrentNav: _updateCurrentNav,
|
|
142
|
+
getPreviousAndNextLink: _getPreviousAndNextLink,
|
|
143
|
+
get: _get
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export const useDocusNavigationState = () => useState(StateTypes.Navigation);
|
|
147
|
+
export const useDocusCurrentNav = () => useState(StateTypes.CurrentNav);
|
|
148
|
+
export const useDocusCurrentPath = () => useState(StateTypes.CurrentPath);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import type { CombinedVueInstance } from 'vue/types/vue';
|
|
3
|
+
import { Context } from '@nuxt/types';
|
|
4
|
+
export declare function createStore<T>(key: string, defaultValue: T): {
|
|
5
|
+
plugin: ({ ssrContext, nuxtState }: Context) => void;
|
|
6
|
+
useStore: (context?: CombinedVueInstance<Vue, object, object, object, Record<never, any>> | Context) => Ref<T>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createStore = createStore;
|
|
7
|
+
|
|
8
|
+
var _app = require("#app");
|
|
9
|
+
|
|
10
|
+
const createPlugin = (key, defaultValue) => {
|
|
11
|
+
const store = (0, _app.ref)(defaultValue || {});
|
|
12
|
+
return ({
|
|
13
|
+
ssrContext,
|
|
14
|
+
nuxtState
|
|
15
|
+
}) => {
|
|
16
|
+
const state = process.server ? ssrContext.nuxt : nuxtState;
|
|
17
|
+
state.stores = state.stores || {};
|
|
18
|
+
|
|
19
|
+
if (process.server) {
|
|
20
|
+
state.stores[key] = store;
|
|
21
|
+
} else {
|
|
22
|
+
Object.assign(store, state.stores?.[key] || {});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function createStore(key, defaultValue) {
|
|
28
|
+
const plugin = createPlugin(key, defaultValue);
|
|
29
|
+
|
|
30
|
+
function useStore(context) {
|
|
31
|
+
if (!context) {
|
|
32
|
+
const vm = (0, _app.getCurrentInstance)();
|
|
33
|
+
if (!vm) throw new Error("useStore must be called in setup() or a context provided");
|
|
34
|
+
context = vm.proxy;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let state;
|
|
38
|
+
|
|
39
|
+
if (process.server) {
|
|
40
|
+
state = "$ssrContext" in context ? context.$ssrContext.nuxt : context.ssrContext?.nuxt;
|
|
41
|
+
} else {
|
|
42
|
+
state = window.__NUXT__;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return state.stores[key];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
plugin,
|
|
50
|
+
useStore
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getCurrentInstance, ref } from "#app";
|
|
2
|
+
const createPlugin = (key, defaultValue) => {
|
|
3
|
+
const store = ref(defaultValue || {});
|
|
4
|
+
return ({ ssrContext, nuxtState }) => {
|
|
5
|
+
const state = process.server ? ssrContext.nuxt : nuxtState;
|
|
6
|
+
state.stores = state.stores || {};
|
|
7
|
+
if (process.server) {
|
|
8
|
+
state.stores[key] = store;
|
|
9
|
+
} else {
|
|
10
|
+
Object.assign(store, state.stores?.[key] || {});
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export function createStore(key, defaultValue) {
|
|
15
|
+
const plugin = createPlugin(key, defaultValue);
|
|
16
|
+
function useStore(context) {
|
|
17
|
+
if (!context) {
|
|
18
|
+
const vm = getCurrentInstance();
|
|
19
|
+
if (!vm)
|
|
20
|
+
throw new Error("useStore must be called in setup() or a context provided");
|
|
21
|
+
context = vm.proxy;
|
|
22
|
+
}
|
|
23
|
+
let state;
|
|
24
|
+
if (process.server) {
|
|
25
|
+
state = "$ssrContext" in context ? context.$ssrContext.nuxt : context.ssrContext?.nuxt;
|
|
26
|
+
} else {
|
|
27
|
+
state = window.__NUXT__;
|
|
28
|
+
}
|
|
29
|
+
return state.stores[key];
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
plugin,
|
|
33
|
+
useStore
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from '@nuxt/types';
|
|
2
|
+
declare function updateHead(): void;
|
|
3
|
+
export declare const createDocusStyles: (context: Context) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Access the styling state and helpers.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useDocusStyles: () => {
|
|
8
|
+
styles: any;
|
|
9
|
+
updateHead: typeof updateHead;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDocusStyles = exports.createDocusStyles = void 0;
|
|
7
|
+
|
|
8
|
+
var _themeColors = require("./theme-colors");
|
|
9
|
+
|
|
10
|
+
var _ = require("./");
|
|
11
|
+
|
|
12
|
+
var _app = require("#app");
|
|
13
|
+
|
|
14
|
+
let _head;
|
|
15
|
+
|
|
16
|
+
function useColors(colors) {
|
|
17
|
+
try {
|
|
18
|
+
return Object.entries(colors).map(([key, color]) => [key, typeof color === "string" ? (0, _themeColors.getColors)(color) : color]);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.warn("Could not parse custom colors:", e && e.message ? e.message : e);
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function useCssVariableStore(scopes = ["dark"]) {
|
|
26
|
+
scopes = ["default", ...scopes];
|
|
27
|
+
|
|
28
|
+
const _store = scopes.reduce((obj, scope) => ({
|
|
29
|
+
[scope]: {},
|
|
30
|
+
...obj
|
|
31
|
+
}), {});
|
|
32
|
+
|
|
33
|
+
const getScope = scope => _store[scope] || null;
|
|
34
|
+
|
|
35
|
+
const putSingle = key => value => {
|
|
36
|
+
const _arr = value.split(":");
|
|
37
|
+
|
|
38
|
+
const _value = _arr.pop();
|
|
39
|
+
|
|
40
|
+
const _scope = getScope(_arr.pop() || "default");
|
|
41
|
+
|
|
42
|
+
if (_scope) {
|
|
43
|
+
_scope[key] = _value;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const put = (key, value) => {
|
|
48
|
+
value.split(" ").map(putSingle(key));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const generateVar = ([key, value]) => `--${key}: ${value}`;
|
|
52
|
+
|
|
53
|
+
const generateScope = scope => {
|
|
54
|
+
const vars = Object.entries(getScope(scope)).map(generateVar).join(";");
|
|
55
|
+
return scope === "default" ? `html:root {${vars}}` : `html.${scope} {${vars}}`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const generate = () => scopes.map(generateScope).join(" ");
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
put,
|
|
62
|
+
generate
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useCSSVariables(colors) {
|
|
67
|
+
const {
|
|
68
|
+
put,
|
|
69
|
+
generate
|
|
70
|
+
} = useCssVariableStore(["dark"]);
|
|
71
|
+
const colorsList = useColors(colors);
|
|
72
|
+
colorsList.forEach(([color, map]) => Object.entries(map).forEach(([variant, value]) => put(`${color}-${variant}`, value)));
|
|
73
|
+
return generate();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function updateHead() {
|
|
77
|
+
const head = typeof _head === "function" ? _head() : _head;
|
|
78
|
+
|
|
79
|
+
if (!Array.isArray(head.style)) {
|
|
80
|
+
head.style = [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!Array.isArray(head.meta)) {
|
|
84
|
+
head.meta = [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
head.style.push({
|
|
88
|
+
hid: "docus-theme",
|
|
89
|
+
cssText: styles.value,
|
|
90
|
+
type: "text/css"
|
|
91
|
+
});
|
|
92
|
+
head.meta = head.meta.filter(s => s.hid !== "theme-color");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const styles = (0, _app.computed)(() => {
|
|
96
|
+
const theme = (0, _.useDocusTheme)();
|
|
97
|
+
return useCSSVariables(theme.value?.colors ? theme.value.colors : {});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const createDocusStyles = context => {
|
|
101
|
+
const {
|
|
102
|
+
app
|
|
103
|
+
} = context;
|
|
104
|
+
_head = app.head;
|
|
105
|
+
updateHead();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
exports.createDocusStyles = createDocusStyles;
|
|
109
|
+
|
|
110
|
+
const useDocusStyles = () => {
|
|
111
|
+
return {
|
|
112
|
+
styles,
|
|
113
|
+
updateHead
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.useDocusStyles = useDocusStyles;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getColors } from "./theme-colors.mjs";
|
|
2
|
+
import { useDocusTheme } from ".//index.mjs";
|
|
3
|
+
import { computed } from "#app";
|
|
4
|
+
let _head;
|
|
5
|
+
function useColors(colors) {
|
|
6
|
+
try {
|
|
7
|
+
return Object.entries(colors).map(([key, color]) => [key, typeof color === "string" ? getColors(color) : color]);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
console.warn("Could not parse custom colors:", e && e.message ? e.message : e);
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function useCssVariableStore(scopes = ["dark"]) {
|
|
14
|
+
scopes = ["default", ...scopes];
|
|
15
|
+
const _store = scopes.reduce((obj, scope) => ({ [scope]: {}, ...obj }), {});
|
|
16
|
+
const getScope = (scope) => _store[scope] || null;
|
|
17
|
+
const putSingle = (key) => (value) => {
|
|
18
|
+
const _arr = value.split(":");
|
|
19
|
+
const _value = _arr.pop();
|
|
20
|
+
const _scope = getScope(_arr.pop() || "default");
|
|
21
|
+
if (_scope) {
|
|
22
|
+
_scope[key] = _value;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const put = (key, value) => {
|
|
26
|
+
value.split(" ").map(putSingle(key));
|
|
27
|
+
};
|
|
28
|
+
const generateVar = ([key, value]) => `--${key}: ${value}`;
|
|
29
|
+
const generateScope = (scope) => {
|
|
30
|
+
const vars = Object.entries(getScope(scope)).map(generateVar).join(";");
|
|
31
|
+
return scope === "default" ? `html:root {${vars}}` : `html.${scope} {${vars}}`;
|
|
32
|
+
};
|
|
33
|
+
const generate = () => scopes.map(generateScope).join(" ");
|
|
34
|
+
return { put, generate };
|
|
35
|
+
}
|
|
36
|
+
function useCSSVariables(colors) {
|
|
37
|
+
const { put, generate } = useCssVariableStore(["dark"]);
|
|
38
|
+
const colorsList = useColors(colors);
|
|
39
|
+
colorsList.forEach(([color, map]) => Object.entries(map).forEach(([variant, value]) => put(`${color}-${variant}`, value)));
|
|
40
|
+
return generate();
|
|
41
|
+
}
|
|
42
|
+
function updateHead() {
|
|
43
|
+
const head = typeof _head === "function" ? _head() : _head;
|
|
44
|
+
if (!Array.isArray(head.style)) {
|
|
45
|
+
head.style = [];
|
|
46
|
+
}
|
|
47
|
+
if (!Array.isArray(head.meta)) {
|
|
48
|
+
head.meta = [];
|
|
49
|
+
}
|
|
50
|
+
head.style.push({
|
|
51
|
+
hid: "docus-theme",
|
|
52
|
+
cssText: styles.value,
|
|
53
|
+
type: "text/css"
|
|
54
|
+
});
|
|
55
|
+
head.meta = head.meta.filter((s) => s.hid !== "theme-color");
|
|
56
|
+
}
|
|
57
|
+
const styles = computed(() => {
|
|
58
|
+
const theme = useDocusTheme();
|
|
59
|
+
return useCSSVariables(theme.value?.colors ? theme.value.colors : {});
|
|
60
|
+
});
|
|
61
|
+
export const createDocusStyles = (context) => {
|
|
62
|
+
const { app } = context;
|
|
63
|
+
_head = app.head;
|
|
64
|
+
updateHead();
|
|
65
|
+
};
|
|
66
|
+
export const useDocusStyles = () => {
|
|
67
|
+
return {
|
|
68
|
+
styles,
|
|
69
|
+
updateHead
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare function parseColor(color?: string): number[];
|
|
2
|
+
export declare function hexValue(components: any): string;
|
|
3
|
+
export declare function tint(components: any, intensity: any): any;
|
|
4
|
+
export declare function shade(components: any, intensity: any): any;
|
|
5
|
+
export declare const withTint: (intensity: any) => (hex: any) => any;
|
|
6
|
+
export declare const withShade: (intensity: any) => (hex: any) => any;
|
|
7
|
+
export declare const _variants: {
|
|
8
|
+
50: (hex: any) => any;
|
|
9
|
+
100: (hex: any) => any;
|
|
10
|
+
200: (hex: any) => any;
|
|
11
|
+
300: (hex: any) => any;
|
|
12
|
+
400: (hex: any) => any;
|
|
13
|
+
500: (c: any) => any;
|
|
14
|
+
600: (hex: any) => any;
|
|
15
|
+
700: (hex: any) => any;
|
|
16
|
+
800: (hex: any) => any;
|
|
17
|
+
900: (hex: any) => any;
|
|
18
|
+
};
|
|
19
|
+
export declare function getColors(color: any, variants?: {
|
|
20
|
+
50: (hex: any) => any;
|
|
21
|
+
100: (hex: any) => any;
|
|
22
|
+
200: (hex: any) => any;
|
|
23
|
+
300: (hex: any) => any;
|
|
24
|
+
400: (hex: any) => any;
|
|
25
|
+
500: (c: any) => any;
|
|
26
|
+
600: (hex: any) => any;
|
|
27
|
+
700: (hex: any) => any;
|
|
28
|
+
800: (hex: any) => any;
|
|
29
|
+
900: (hex: any) => any;
|
|
30
|
+
}): {};
|