From 5e3fc81d096badbc200b5cfd8a49177673c095d6 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 23:43:12 +0800 Subject: [PATCH] [add] sui page render wrapper option --- sui/core/build.go | 4 ++++ sui/core/editor.go | 18 +++++++++++++++++- sui/core/types.go | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sui/core/build.go b/sui/core/build.go index 0971b9d7b2..7d7d68516e 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -197,6 +197,10 @@ func (page *Page) BuildHTML(option *BuildOption) (string, error) { html := string(page.Codes.HTML.Code) + if option.WithWrapper { + html = fmt.Sprintf("%s", html) + } + if !option.IgnoreDocument { html = string(page.Document) if page.Codes.HTML.Code != "" { diff --git a/sui/core/editor.go b/sui/core/editor.go index c5987726dc..81d8345154 100644 --- a/sui/core/editor.go +++ b/sui/core/editor.go @@ -48,6 +48,7 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) { SSR: true, IgnoreAssetRoot: true, IgnoreDocument: true, + WithWrapper: true, KeepPageTag: true, }) @@ -59,10 +60,25 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) { res.Warnings = append(res.Warnings, warnings...) } - res.HTML, err = doc.Html() + // Block save event + // jsCode := ` + // console.log("hello ifrme") + // document.addEventListener('keydown', function (event) { + // const isCtrlOrCmdPressed = event.ctrlKey || event.metaKey; + // const isSPressed = event.key === 's'; + // if (isCtrlOrCmdPressed && isSPressed) { + // event.preventDefault(); + // console.log('Control/Command + S pressed in iframe! Default save behavior prevented.'); + // } + // }); + // ` + // jsCode := ` console.log("hello ifrme")` + // doc.Find("body").AppendHtml(``) + res.HTML, err = doc.Find("body").Html() if err != nil { return nil, err } + // fmt.Println(res.HTML) var data Data = nil if page.Codes.DATA.Code != "" { diff --git a/sui/core/types.go b/sui/core/types.go index 1b698a8ed6..bee73eae67 100644 --- a/sui/core/types.go +++ b/sui/core/types.go @@ -141,6 +141,7 @@ type BuildOption struct { AssetRoot string `json:"asset_root,omitempty"` IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"` IgnoreDocument bool `json:"ignore_document,omitempty"` + WithWrapper bool `json:"with_wrapper,omitempty"` KeepPageTag bool `json:"keep_page_tag,omitempty"` Namespace string `json:"namespace,omitempty"` }