UNPKG

@wordpress/edit-post

Version:
283 lines (281 loc) 11.1 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/edit-post/src/index.js var index_exports = {}; __export(index_exports, { __experimentalFullscreenModeClose: () => import_fullscreen_mode_close.default, __experimentalMainDashboardButton: () => __experimentalMainDashboardButton, initializeEditor: () => initializeEditor, reinitializeEditor: () => reinitializeEditor, store: () => import_store.store }); module.exports = __toCommonJS(index_exports); var import_blocks = require("@wordpress/blocks"); var import_block_library = require("@wordpress/block-library"); var import_deprecated = __toESM(require("@wordpress/deprecated")); var import_element = require("@wordpress/element"); var import_data = require("@wordpress/data"); var import_preferences = require("@wordpress/preferences"); var import_widgets = require("@wordpress/widgets"); var import_editor = require("@wordpress/editor"); var import_core_data = require("@wordpress/core-data"); var import_api_fetch = __toESM(require("@wordpress/api-fetch")); var import_layout = __toESM(require("./components/layout/index.cjs")); var import_lock_unlock = require("./lock-unlock.cjs"); var import_fullscreen_mode_close = __toESM(require("./components/back-button/fullscreen-mode-close.cjs")); var import_store = require("./store/index.cjs"); __reExport(index_exports, require("./deprecated.cjs"), module.exports); var import_jsx_runtime = require("react/jsx-runtime"); var { BackButton: __experimentalMainDashboardButton, registerCoreBlockBindingsSources } = (0, import_lock_unlock.unlock)(import_editor.privateApis); var { enablePreloadMultiUse, clearPreloadedData } = (0, import_lock_unlock.unlock)( import_api_fetch.default.privateApis ); function initializeEditor(id, postType, postId, settings, initialEdits) { const isMediumOrBigger = window.matchMedia("(min-width: 782px)").matches; const target = document.getElementById(id); const root = (0, import_element.createRoot)(target); (0, import_data.dispatch)(import_preferences.store).setDefaults("core/edit-post", { fullscreenMode: true, themeStyles: true, welcomeGuide: true, welcomeGuideTemplate: true }); (0, import_data.dispatch)(import_preferences.store).setDefaults("core", { allowRightClickOverrides: true, editorMode: "visual", editorTool: "edit", fixedToolbar: false, hiddenBlockTypes: [], inactivePanels: [], openPanels: ["post-status"], showBlockBreadcrumbs: true, showIconLabels: false, showListViewByDefault: false, enableChoosePatternModal: true, isPublishSidebarEnabled: true, showCollaborationCursor: false, showCollaborationJoinNotifications: true, showCollaborationLeaveNotifications: true, showCollaborationPostSaveNotifications: true }); if (window.__clientSideMediaProcessing) { (0, import_data.dispatch)(import_preferences.store).setDefaults("core/media", { requireApproval: true, optimizeOnUpload: true }); } (0, import_data.dispatch)(import_blocks.store).reapplyBlockTypeFilters(); if (isMediumOrBigger && (0, import_data.select)(import_preferences.store).get("core", "showListViewByDefault") && !(0, import_data.select)(import_preferences.store).get("core", "distractionFree")) { (0, import_data.dispatch)(import_editor.store).setIsListViewOpened(true); } (0, import_block_library.registerCoreBlocks)(); registerCoreBlockBindingsSources(); (0, import_widgets.registerLegacyWidgetBlock)({ inserter: false }); (0, import_widgets.registerWidgetGroupBlock)({ inserter: false }); if (globalThis.IS_GUTENBERG_PLUGIN) { (0, import_block_library.__experimentalRegisterExperimentalCoreBlocks)({ enableFSEBlocks: settings.__unstableEnableFullSiteEditingBlocks }); } const documentMode = document.compatMode === "CSS1Compat" ? "Standards" : "Quirks"; if (documentMode !== "Standards") { console.warn( "Your browser is using Quirks Mode. \nThis can cause rendering issues such as blocks overlaying meta boxes in the editor. Quirks Mode can be triggered by PHP errors or HTML code appearing before the opening <!DOCTYPE html>. Try checking the raw page source or your site's PHP error log and resolving errors there, removing any HTML before the doctype, or disabling plugins." ); } window.addEventListener("dragover", (e) => e.preventDefault(), false); window.addEventListener("drop", (e) => e.preventDefault(), false); enablePreloadMultiUse(); const preloadedResolutions = preloadResolutions(postType, postId); preloadedResolutions.finally(() => { clearPreloadedData(); if (postType && postId) { const post = (0, import_data.select)(import_core_data.store).getEntityRecord( "postType", postType, postId ); if (post) { (0, import_data.dispatch)(import_editor.store).setupEditor( post, initialEdits, settings.template ); } } root.render( /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_layout.default, { settings, postId, postType, initialEdits } ) }) ); }); return root; } async function preloadResolutions(postType, postId) { const core = (0, import_data.resolveSelect)(import_core_data.store); const coreSelect = (0, import_data.select)(import_core_data.store); try { await Promise.all([ core.getCurrentUser(), core.getEntitiesConfig("postType"), core.getEntitiesConfig("taxonomy"), core.getEntitiesConfig("root"), core.getEntityRecords("root", "taxonomy"), core.getCurrentTheme(), // Forward-resolver alias of `getCurrentTheme` with its own // resolution metadata, so it needs a separate kick. core.getThemeSupports(), core.getBlockPatternCategories(), core.__experimentalGetCurrentGlobalStylesId(), core.__experimentalGetCurrentThemeBaseGlobalStyles(), core.__experimentalGetCurrentThemeGlobalStylesVariations(), core.getEntityRecord("root", "__unstableBase"), core.canUser("read", { kind: "root", name: "site" }), core.canUser("create", { kind: "postType", name: "attachment" }), core.canUser("create", { kind: "postType", name: "page" }), core.canUser("create", { kind: "postType", name: "wp_block" }), core.canUser("create", { kind: "postType", name: "wp_template" }), // The DataForm-based inspector requests the entity form config // when the document sidebar mounts. The args must match the // `useViewConfig` call in `@wordpress/views` exactly for the // resolution (and its preload entry) to be shared. ...postType && window?.__experimentalDataFormInspector ? [ (0, import_lock_unlock.unlock)(core).getViewConfig("postType", postType, { fields: "form" }) ] : [], // Per-post resolvers. `getPostType` and `getEditedEntityRecord` // are shorthand/forward-resolver aliases with their own // resolution metadata, so they need separate kicks. ...postType && postId ? [ core.getPostType(postType), core.getEntityRecord("postType", postType, postId), core.getEditedEntityRecord( "postType", postType, postId ), core.getAutosaves(postType, postId), core.getDefaultTemplateId({ slug: "front-page" }), core.canUser("create", { kind: "postType", name: postType }) ] : [] ]); const tasks = []; if (coreSelect.canUser("read", { kind: "root", name: "site" })) { tasks.push(core.getEntityRecord("root", "site")); } const globalStylesId = coreSelect.__experimentalGetCurrentGlobalStylesId(); if (globalStylesId) { tasks.push( core.canUser("update", { kind: "root", name: "globalStyles", id: globalStylesId }) ); } if (postType && postId) { const post = coreSelect.getEntityRecord( "postType", postType, postId ); if (post) { let slug = "page" === postType ? "page" : "single-" + postType; if (post.slug) { slug += "-" + post.slug; } tasks.push(core.getDefaultTemplateId({ slug })); if (post.author) { tasks.push( core.getUser(post.author, { context: "view", _fields: "id,name" }) ); } } } if (tasks.length) { await Promise.all(tasks); } if (globalStylesId) { if (coreSelect.canUser("update", { kind: "root", name: "globalStyles", id: globalStylesId })) { await core.getEntityRecord( "root", "globalStyles", globalStylesId ); } else { await core.getEntityRecord( "root", "globalStyles", globalStylesId, { context: "view" } ); } } } catch { } } function reinitializeEditor() { (0, import_deprecated.default)("wp.editPost.reinitializeEditor", { since: "6.2", version: "6.3" }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { __experimentalFullscreenModeClose, __experimentalMainDashboardButton, initializeEditor, reinitializeEditor, store, ...require("./deprecated.cjs") }); //# sourceMappingURL=index.cjs.map