1 | "use strict";
|
2 |
|
3 |
|
4 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
5 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
6 | };
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | exports.PageConfig = void 0;
|
9 | const coreutils_1 = require("@lumino/coreutils");
|
10 | const minimist_1 = __importDefault(require("minimist"));
|
11 | const url_1 = require("./url");
|
12 |
|
13 |
|
14 |
|
15 | var PageConfig;
|
16 | (function (PageConfig) {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function getOption(name) {
|
36 | if (configData) {
|
37 | return configData[name] || getBodyData(name);
|
38 | }
|
39 | configData = Object.create(null);
|
40 | let found = false;
|
41 |
|
42 | if (typeof document !== 'undefined' && document) {
|
43 | const el = document.getElementById('jupyter-config-data');
|
44 | if (el) {
|
45 | configData = JSON.parse(el.textContent || '');
|
46 | found = true;
|
47 | }
|
48 | }
|
49 |
|
50 | if (!found && typeof process !== 'undefined' && process.argv) {
|
51 | try {
|
52 | const cli = (0, minimist_1.default)(process.argv.slice(2));
|
53 | const path = require('path');
|
54 | let fullPath = '';
|
55 | if ('jupyter-config-data' in cli) {
|
56 | fullPath = path.resolve(cli['jupyter-config-data']);
|
57 | }
|
58 | else if ('JUPYTER_CONFIG_DATA' in process.env) {
|
59 | fullPath = path.resolve(process.env['JUPYTER_CONFIG_DATA']);
|
60 | }
|
61 | if (fullPath) {
|
62 |
|
63 |
|
64 | configData = eval('require')(fullPath);
|
65 | }
|
66 | }
|
67 | catch (e) {
|
68 | console.error(e);
|
69 | }
|
70 | }
|
71 | if (!coreutils_1.JSONExt.isObject(configData)) {
|
72 | configData = Object.create(null);
|
73 | }
|
74 | else {
|
75 | for (const key in configData) {
|
76 |
|
77 | if (typeof configData[key] !== 'string') {
|
78 | configData[key] = JSON.stringify(configData[key]);
|
79 | }
|
80 | }
|
81 | }
|
82 | return configData[name] || getBodyData(name);
|
83 | }
|
84 | PageConfig.getOption = getOption;
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | function setOption(name, value) {
|
94 | const last = getOption(name);
|
95 | configData[name] = value;
|
96 | return last;
|
97 | }
|
98 | PageConfig.setOption = setOption;
|
99 | |
100 |
|
101 |
|
102 | function getBaseUrl() {
|
103 | return url_1.URLExt.normalize(getOption('baseUrl') || '/');
|
104 | }
|
105 | PageConfig.getBaseUrl = getBaseUrl;
|
106 | |
107 |
|
108 |
|
109 | function getTreeUrl() {
|
110 | return url_1.URLExt.join(getBaseUrl(), getOption('treeUrl'));
|
111 | }
|
112 | PageConfig.getTreeUrl = getTreeUrl;
|
113 | |
114 |
|
115 |
|
116 | function getShareUrl() {
|
117 | return url_1.URLExt.normalize(getOption('shareUrl') || getBaseUrl());
|
118 | }
|
119 | PageConfig.getShareUrl = getShareUrl;
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 | function getTreeShareUrl() {
|
126 | return url_1.URLExt.normalize(url_1.URLExt.join(getShareUrl(), getOption('treeUrl')));
|
127 | }
|
128 | PageConfig.getTreeShareUrl = getTreeShareUrl;
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | function getUrl(options) {
|
139 | var _a, _b, _c, _d;
|
140 | let path = options.toShare ? getShareUrl() : getBaseUrl();
|
141 | const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : getOption('mode');
|
142 | const workspace = (_b = options.workspace) !== null && _b !== void 0 ? _b : getOption('workspace');
|
143 | const labOrDoc = mode === 'single-document' ? 'doc' : 'lab';
|
144 | path = url_1.URLExt.join(path, labOrDoc);
|
145 | if (workspace !== PageConfig.defaultWorkspace) {
|
146 | path = url_1.URLExt.join(path, 'workspaces', encodeURIComponent((_c = getOption('workspace')) !== null && _c !== void 0 ? _c : PageConfig.defaultWorkspace));
|
147 | }
|
148 | const treePath = (_d = options.treePath) !== null && _d !== void 0 ? _d : getOption('treePath');
|
149 | if (treePath) {
|
150 | path = url_1.URLExt.join(path, 'tree', url_1.URLExt.encodeParts(treePath));
|
151 | }
|
152 | return path;
|
153 | }
|
154 | PageConfig.getUrl = getUrl;
|
155 | PageConfig.defaultWorkspace = 'default';
|
156 | |
157 |
|
158 |
|
159 | function getWsUrl(baseUrl) {
|
160 | let wsUrl = getOption('wsUrl');
|
161 | if (!wsUrl) {
|
162 | baseUrl = baseUrl ? url_1.URLExt.normalize(baseUrl) : getBaseUrl();
|
163 | if (baseUrl.indexOf('http') !== 0) {
|
164 | return '';
|
165 | }
|
166 | wsUrl = 'ws' + baseUrl.slice(4);
|
167 | }
|
168 | return url_1.URLExt.normalize(wsUrl);
|
169 | }
|
170 | PageConfig.getWsUrl = getWsUrl;
|
171 | |
172 |
|
173 |
|
174 |
|
175 | function getNBConvertURL({ path, format, download }) {
|
176 | const notebookPath = url_1.URLExt.encodeParts(path);
|
177 | const url = url_1.URLExt.join(getBaseUrl(), 'nbconvert', format, notebookPath);
|
178 | if (download) {
|
179 | return url + '?download=true';
|
180 | }
|
181 | return url;
|
182 | }
|
183 | PageConfig.getNBConvertURL = getNBConvertURL;
|
184 | |
185 |
|
186 |
|
187 | function getToken() {
|
188 | return getOption('token') || getBodyData('jupyterApiToken');
|
189 | }
|
190 | PageConfig.getToken = getToken;
|
191 | |
192 |
|
193 |
|
194 | function getNotebookVersion() {
|
195 | const notebookVersion = getOption('notebookVersion');
|
196 | if (notebookVersion === '') {
|
197 | return [0, 0, 0];
|
198 | }
|
199 | return JSON.parse(notebookVersion);
|
200 | }
|
201 | PageConfig.getNotebookVersion = getNotebookVersion;
|
202 | |
203 |
|
204 |
|
205 | let configData = null;
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 | function getBodyData(key) {
|
212 | if (typeof document === 'undefined' || !document.body) {
|
213 | return '';
|
214 | }
|
215 | const val = document.body.dataset[key];
|
216 | if (typeof val === 'undefined') {
|
217 | return '';
|
218 | }
|
219 | return decodeURIComponent(val);
|
220 | }
|
221 | |
222 |
|
223 |
|
224 | let Extension;
|
225 | (function (Extension) {
|
226 | |
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | function populate(key) {
|
235 | try {
|
236 | const raw = getOption(key);
|
237 | if (raw) {
|
238 | return JSON.parse(raw);
|
239 | }
|
240 | }
|
241 | catch (error) {
|
242 | console.warn(`Unable to parse ${key}.`, error);
|
243 | }
|
244 | return [];
|
245 | }
|
246 | |
247 |
|
248 |
|
249 | Extension.deferred = populate('deferredExtensions');
|
250 | |
251 |
|
252 |
|
253 | Extension.disabled = populate('disabledExtensions');
|
254 | |
255 |
|
256 |
|
257 |
|
258 |
|
259 | function isDeferred(id) {
|
260 |
|
261 |
|
262 | const separatorIndex = id.indexOf(':');
|
263 | let extName = '';
|
264 | if (separatorIndex !== -1) {
|
265 | extName = id.slice(0, separatorIndex);
|
266 | }
|
267 | return Extension.deferred.some(val => val === id || (extName && val === extName));
|
268 | }
|
269 | Extension.isDeferred = isDeferred;
|
270 | |
271 |
|
272 |
|
273 |
|
274 |
|
275 | function isDisabled(id) {
|
276 |
|
277 |
|
278 | const separatorIndex = id.indexOf(':');
|
279 | let extName = '';
|
280 | if (separatorIndex !== -1) {
|
281 | extName = id.slice(0, separatorIndex);
|
282 | }
|
283 | return Extension.disabled.some(val => val === id || (extName && val === extName));
|
284 | }
|
285 | Extension.isDisabled = isDisabled;
|
286 | })(Extension = PageConfig.Extension || (PageConfig.Extension = {}));
|
287 | })(PageConfig || (exports.PageConfig = PageConfig = {}));
|
288 |
|
\ | No newline at end of file |