This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(editor-export): image block workflow#298
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
d10f5ce
refactor(editor-export): single image workflow
mydearxym5387a57
refactor(editor-export): jiugongge(九宫格) image workflow
mydearxym201cfa9
refactor(editor-export): gallery image workflow
mydearxymb99e63c
refactor(editor-export): gallery minimap scroll ux
mydearxym3e75436
test(editor-export): invalid data test for image block
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletionslib/helper/converter/editor_to_html/class.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletionslib/helper/converter/editor_to_html/frags/image.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
defmodule Helper.Converter.EditorToHTML.Frags.Image do | ||
@moduledoc """ | ||
parse editor.js's block fragments, use for test too | ||
see https://editorjs.io/ | ||
""" | ||
import Helper.Validator.Guards, only: [g_none_empty_str: 1] | ||
alias Helper.Converter.EditorToHTML.Class | ||
alias Helper.Types, as: T | ||
@class get_in(Class.article(), ["image"]) | ||
@spec get_item(:single | :gallery | :jiugongge, T.editor_image_item()) :: T.html() | ||
def get_item( | ||
:single, | ||
%{ | ||
"src" => src, | ||
"width" => width, | ||
"height" => height | ||
} = data | ||
) | ||
when g_none_empty_str(width) and g_none_empty_str(height) do | ||
caption = get_caption(data) | ||
image_wrapper_class = @class["single_image_wrapper"] | ||
image_class = @class["single_image"] | ||
~s(<div class="#{image_wrapper_class}"> | ||
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}"> | ||
<img class="#{image_class}" style="width:#{width}; height:#{height}" src="#{src}" alt="image" /> | ||
</a> | ||
</div>) | ||
end | ||
def get_item(:single, %{"src" => src} = data) do | ||
caption = get_caption(data) | ||
image_wrapper_class = @class["single_image_wrapper"] | ||
image_class = @class["single_image"] | ||
~s(<div class="#{image_wrapper_class}"> | ||
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}"> | ||
<img class="#{image_class}" src="#{src}" alt="image" /> | ||
</a> | ||
</div>) | ||
end | ||
def get_item(:jiugongge, %{"src" => src} = data) do | ||
caption = get_caption(data) | ||
# image_wrapper_class = @class["jiugongge-image"] | ||
jiugongge_image_block_class = @class["jiugongge_image_block"] | ||
image_class = @class["jiugongge_image"] | ||
~s(<div class="#{jiugongge_image_block_class}"> | ||
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}"> | ||
<img class="#{image_class}" src="#{src}" alt="image" /> | ||
</a> | ||
</div>) | ||
end | ||
def get_item(:gallery, %{"src" => src, "index" => index} = data) do | ||
caption = get_caption(data) | ||
gallery_image_block_class = @class["gallery_image_block"] | ||
image_class = @class["gallery_image"] | ||
# IO.inspect(index, label: "index -> ") | ||
~s(<div class="#{gallery_image_block_class}"> | ||
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}"> | ||
<img class="#{image_class}" src="#{src}" alt="image" data-index="#{index}" /> | ||
</a> | ||
</div>) | ||
end | ||
@spec get_minimap([T.editor_image_item()]) :: T.html() | ||
def get_minimap(items) do | ||
wrapper_class = @class["gallery_minimap"] | ||
items_content = | ||
Enum.reduce(items, "", fn item, acc -> | ||
acc <> frag(:minimap_image, item) | ||
end) | ||
~s(<div class="#{wrapper_class}"> | ||
#{items_content} | ||
</div>) | ||
end | ||
defp frag(:minimap_image, %{"src" => src, "index" => index}) do | ||
image_class = @class["gallery_minimap_image"] | ||
~s(<img class="#{image_class}" src="#{src}" data-index="#{index}"/>) | ||
end | ||
def get_caption(%{"caption" => caption}) when g_none_empty_str(caption), do: caption | ||
def get_caption(_), do: "" | ||
def get_caption(:html, %{"caption" => caption}) when g_none_empty_str(caption) do | ||
image_caption = @class["image_caption"] | ||
~s(<div class="#{image_caption}">#{caption}</div>) | ||
end | ||
def get_caption(:html, _), do: "" | ||
# @spec frag(:checkbox, :text, String.t()) :: T.html() | ||
# def frag(:checkbox, :text, text) do | ||
# text_class = @class["checklist_text"] | ||
# ~s(<div class="#{text_class}"> | ||
# #{text} | ||
# </div>) | ||
# end | ||
# defp svg(type) do | ||
# # workarround for https://github.com/rrrene/html_sanitize_ex/issues/48 | ||
# svg_frag(type) |> String.replace(" viewBox=\"", " viewbox=\"") | ||
# end | ||
# defp svg_frag(:checked) do | ||
# ~s(<svg t="1592049095081" width="20px" height="20px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9783"><path d="M853.333333 256L384 725.333333l-213.333333-213.333333" p-id="9784"></path></svg>) | ||
# end | ||
end |
2 changes: 2 additions & 0 deletionslib/helper/converter/editor_to_html/frontend_test/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
42 changes: 39 additions & 3 deletionslib/helper/converter/editor_to_html/frontend_test/script.js
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
138 changes: 136 additions & 2 deletionslib/helper/converter/editor_to_html/frontend_test/styles.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.