From 6fedf2d828889cebb4f1f9d7d03766c321329197 Mon Sep 17 00:00:00 2001 From: Heather Yu Date: Mon, 1 May 2023 14:20:21 -0400 Subject: [PATCH] fix: overwrite default data-slate-editor styling imports custom styling so that cursor does not jump to end of line on edit --- .../src/cms/admin/admin.css | 3 +++ .../src/cms/cms-utils.js | 26 +++++++++++++++++++ .../src/cms/cms.js | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 packages/project-portal-content-netlify/src/cms/admin/admin.css create mode 100644 packages/project-portal-content-netlify/src/cms/cms-utils.js diff --git a/packages/project-portal-content-netlify/src/cms/admin/admin.css b/packages/project-portal-content-netlify/src/cms/admin/admin.css new file mode 100644 index 000000000..f1be6712b --- /dev/null +++ b/packages/project-portal-content-netlify/src/cms/admin/admin.css @@ -0,0 +1,3 @@ +[data-slate-editor] { + -webkit-user-modify: read-write !important; +} diff --git a/packages/project-portal-content-netlify/src/cms/cms-utils.js b/packages/project-portal-content-netlify/src/cms/cms-utils.js new file mode 100644 index 000000000..d7073b595 --- /dev/null +++ b/packages/project-portal-content-netlify/src/cms/cms-utils.js @@ -0,0 +1,26 @@ +if (typeof window !== 'undefined') { + + // add admin.css + const link = document.createElement('link') + link.type = 'text/css' + link.rel = 'stylesheet' + link.href = '/admin/admin.css' + document.head.appendChild(link) + + if (process.env.NETLIFY_SITE_URL) { + window.localStorage.setItem( + 'netlifySiteURL', process.env.NETLIFY_SITE_URL + ) + } + + // Log netlifySiteURL if editing on localhost + if ( + window.location.hostname === 'localhost' && + window.localStorage.getItem('netlifySiteURL') + ) { + console.log( + `%cnetlifySiteURL: ${window.localStorage.getItem('netlifySiteURL')}`, + 'color: hotpink; font-size: 15px' + ) + } +} diff --git a/packages/project-portal-content-netlify/src/cms/cms.js b/packages/project-portal-content-netlify/src/cms/cms.js index 15ee73db1..b9e150208 100644 --- a/packages/project-portal-content-netlify/src/cms/cms.js +++ b/packages/project-portal-content-netlify/src/cms/cms.js @@ -1,5 +1,8 @@ import CMS from "netlify-cms-app" +// Add custom styles to the index.html page +import "./cms-utils" + // The following configuration is merged with the configuration from the site's config.yml file // (if it exists in the site's directory static/admin/config.yml) CMS.init({