@fails-components/jupyter-filesystem-extension
Version:
A collection of extensions, that redirect's filesystems access to fails and let fails puppeteer Jupyter lite.
84 lines (83 loc) • 3.2 kB
JavaScript
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { SettingManager } from '@jupyterlab/services';
import * as json5 from 'json5';
class FailsSettings extends SettingManager {
static override(plugin) {
if (FailsSettings._overrides[plugin.id]) {
if (!plugin.schema.properties) {
// probably malformed, or only provides keyboard shortcuts, etc.
plugin.schema.properties = {};
}
for (const [prop, propDefault] of Object.entries(FailsSettings._overrides[plugin.id] || {})) {
plugin.schema.properties[prop].default = propDefault;
}
}
return plugin;
}
constructor(options) {
super({
serverSettings: options.serverSettings
});
}
// copied from the original settings (updated)
async fetch(pluginId) {
const all = await this.list();
const settings = all.values;
const setting = settings.find((setting) => {
return setting.id === pluginId;
});
if (!setting) {
throw new Error(`Setting ${pluginId} not found`);
}
return setting;
}
// copied from the original settings (updated)
async list(query) {
var _a, _b;
const allCore = await this._getAll('all.json');
let allFederated = [];
try {
allFederated = await this._getAll('all_federated.json');
}
catch (_c) {
// handle the case where there is no federated extension
}
// JupyterLab 4 expects all settings to be returned in one go
// so append the settings from federated plugins to the core ones
const all = allCore.concat(allFederated);
// return existing user settings if they exist
const settings = await Promise.all(all.map(async (plugin) => {
// const { id } = plugin;
const raw = /*((await storage.getItem(id)) as string) ?? */ plugin.raw;
return {
...FailsSettings.override(plugin),
raw,
settings: json5.parse(raw)
};
}));
// format the settings
const ids = (_a = settings.map((plugin) => plugin.id)) !== null && _a !== void 0 ? _a : [];
let values = [];
if (!query) {
values =
(_b = settings.map((plugin) => {
plugin.data = { composite: {}, user: {} };
return plugin;
})) !== null && _b !== void 0 ? _b : [];
}
return { ids, values };
}
// one to one copy from settings of the original JupyterLite
async _getAll(file) {
var _a;
const settingsUrl = (_a = PageConfig.getOption('settingsUrl')) !== null && _a !== void 0 ? _a : '/';
const all = (await (await fetch(URLExt.join(settingsUrl, file))).json());
return all;
}
async save(id, raw) {
// we do nothing
}
}
// the following is copied from the original Jupyter Lite Settings Object
FailsSettings._overrides = JSON.parse(PageConfig.getOption('settingsOverrides') || '{}');
export { FailsSettings };