From 6fedf2d828889cebb4f1f9d7d03766c321329197 Mon Sep 17 00:00:00 2001 From: Heather Yu Date: Mon, 1 May 2023 14:20:21 -0400 Subject: [PATCH 1/5] 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({ From 418664aa3314b06d2abf2a6b54371c59a259f748 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Mon, 1 May 2023 14:24:20 -0400 Subject: [PATCH 2/5] doc: remove console log --- .../src/cms/cms-utils.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/project-portal-content-netlify/src/cms/cms-utils.js b/packages/project-portal-content-netlify/src/cms/cms-utils.js index d7073b595..e5ea97104 100644 --- a/packages/project-portal-content-netlify/src/cms/cms-utils.js +++ b/packages/project-portal-content-netlify/src/cms/cms-utils.js @@ -13,14 +13,4 @@ if (typeof window !== 'undefined') { ) } - // 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' - ) - } } From b6dd0e8fa610ca9743c142d6d31019f05eb6e48d Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 2 May 2023 11:17:16 -0400 Subject: [PATCH 3/5] move admin.css to static/admin --- .../static}/admin/admin.css | 0 .../src/cms/cms-utils.js | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) rename packages/{project-portal-content-netlify/src/cms => example-site/static}/admin/admin.css (100%) diff --git a/packages/project-portal-content-netlify/src/cms/admin/admin.css b/packages/example-site/static/admin/admin.css similarity index 100% rename from packages/project-portal-content-netlify/src/cms/admin/admin.css rename to packages/example-site/static/admin/admin.css diff --git a/packages/project-portal-content-netlify/src/cms/cms-utils.js b/packages/project-portal-content-netlify/src/cms/cms-utils.js index e5ea97104..6e7c42543 100644 --- a/packages/project-portal-content-netlify/src/cms/cms-utils.js +++ b/packages/project-portal-content-netlify/src/cms/cms-utils.js @@ -1,16 +1,25 @@ -if (typeof window !== 'undefined') { - +if (typeof window !== "undefined") { // add admin.css - const link = document.createElement('link') - link.type = 'text/css' - link.rel = 'stylesheet' - link.href = '/admin/admin.css' + const link = document.createElement("link") + link.type = "text/css" + link.rel = "stylesheet" + link.href = "/admin/admin.css" document.head.appendChild(link) + console.log(link.href) + console.log() if (process.env.NETLIFY_SITE_URL) { - window.localStorage.setItem( - 'netlifySiteURL', 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" + ) + } } From f5dfeb63ca9f36f2d4c26f400d84a982861003fe Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 2 May 2023 16:08:32 -0400 Subject: [PATCH 4/5] fix: try manually setting a styles tag in netlify head --- .../src/cms/cms-utils.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/project-portal-content-netlify/src/cms/cms-utils.js b/packages/project-portal-content-netlify/src/cms/cms-utils.js index 6e7c42543..1e2982a3c 100644 --- a/packages/project-portal-content-netlify/src/cms/cms-utils.js +++ b/packages/project-portal-content-netlify/src/cms/cms-utils.js @@ -1,12 +1,16 @@ 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) - console.log(link.href) - console.log() + const styles = + "[data-slate-editor] {-webkit-user-modify: read-write !important;" + "}\n" + const css = document.createElement("style") + css.type = "text/css" + if (css.styleSheet) { + css.styleSheet.cssText = styles + } else { + css.appendChild(document.createTextNode(styles)) + } + + document.head.appendChild(css) if (process.env.NETLIFY_SITE_URL) { window.localStorage.setItem("netlifySiteURL", process.env.NETLIFY_SITE_URL) From e5df61d860f82e3b65ce461506bc089c841f336f Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 2 May 2023 16:27:26 -0400 Subject: [PATCH 5/5] fix: prepare tarball --- .../src/cms}/admin/admin.css | 0 .../src/cms/cms-utils.js | 33 ++++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) rename packages/{example-site/static => project-portal-content-netlify/src/cms}/admin/admin.css (100%) diff --git a/packages/example-site/static/admin/admin.css b/packages/project-portal-content-netlify/src/cms/admin/admin.css similarity index 100% rename from packages/example-site/static/admin/admin.css rename to packages/project-portal-content-netlify/src/cms/admin/admin.css diff --git a/packages/project-portal-content-netlify/src/cms/cms-utils.js b/packages/project-portal-content-netlify/src/cms/cms-utils.js index 1e2982a3c..e5ea97104 100644 --- a/packages/project-portal-content-netlify/src/cms/cms-utils.js +++ b/packages/project-portal-content-netlify/src/cms/cms-utils.js @@ -1,29 +1,16 @@ -if (typeof window !== "undefined") { - // add admin.css - const styles = - "[data-slate-editor] {-webkit-user-modify: read-write !important;" + "}\n" - const css = document.createElement("style") - css.type = "text/css" - if (css.styleSheet) { - css.styleSheet.cssText = styles - } else { - css.appendChild(document.createTextNode(styles)) - } +if (typeof window !== 'undefined') { - document.head.appendChild(css) + // 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" + window.localStorage.setItem( + 'netlifySiteURL', process.env.NETLIFY_SITE_URL ) } + }