UNPKG

@silexlabs/grapesjs-data-source

Version:
99 lines 4.57 kB
"use strict"; /* * Silex website builder, free/libre no-code tool for makers. * Copyright (c) 2023 lexoyo and Silex Labs foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.version = void 0; const commands_1 = __importDefault(require("./commands")); const capabilities_1 = require("./capabilities"); const dataSourceManager_1 = require("./model/dataSourceManager"); const storage_1 = __importDefault(require("./storage")); const types_1 = require("./types"); const utils_1 = require("./utils"); const view_1 = __importDefault(require("./view")); /** * Export the public API */ // Main public API - this is what apps should use __exportStar(require("./api"), exports); // Types and interfaces that apps need __exportStar(require("./types"), exports); /** * GrapeJs plugin entry point */ exports.default = (editor, opts = {}) => { const options = Object.assign(Object.assign({ dataSources: [], filters: [], previewActive: true }, opts), { view: Object.assign({ el: '.gjs-pn-panel.gjs-pn-views-container' }, opts === null || opts === void 0 ? void 0 : opts.view) }); const dataSources = options.dataSources // Make sure the data sources from the config are readonly .map(ds => (Object.assign(Object.assign({}, ds), { readonly: true }))) // Create the data sources from config .map((ds) => (0, utils_1.createDataSource)(ds)); // Connect the data sources (async) Promise.all(dataSources .map(ds => { return ds.connect() .catch(err => console.error(`Data source ${ds.id} connection failed:`, err)); })) .catch(err => console.error('Error while connecting data sources', err)); // Initialize the global data source manager (0, dataSourceManager_1.initializeDataSourceManager)(dataSources, editor, options); // Register the UI for component properties (0, view_1.default)(editor, options); // Save and load data sources (0, storage_1.default)(editor); // Register the commands (0, commands_1.default)(editor, options); // Use grapesjs-notifications plugin for errors editor.on(types_1.DATA_SOURCE_ERROR, (msg, ds) => editor.runCommand('notifications:add', { type: 'error', message: `Data source \`${ds.id}\` error: ${msg}`, group: utils_1.NOTIFICATION_GROUP })); // Load data after editor is fully loaded editor.on('load', () => { (0, dataSourceManager_1.refreshDataSources)(); }); // Also refresh data when storage loads (to handle website data loading) editor.on('storage:end:load', () => { // Use setTimeout to ensure components are fully loaded setTimeout(() => { (0, dataSourceManager_1.refreshDataSources)(); }, 100); }); // Register AI capabilities if grapesjs-ai-capabilities is loaded editor.on('ai-capabilities:ready', (addCapability) => { (0, capabilities_1.registerCapabilities)(addCapability); }); }; /** * Version of the plugin * This is replaced by the build script */ exports.version = '__VERSION__'; //# sourceMappingURL=index.js.map