-
Notifications
You must be signed in to change notification settings - Fork 130
HAR-9460 - handle alternate content node #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
47 changes: 47 additions & 0 deletions
47
packages/super-editor/src/core/super-converter/v2/importer/alternateChoiceImporter.js
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,47 @@ | ||
| /** | ||
| * @type {import("docxImporter").NodeHandler} | ||
| */ | ||
| const handleAlternateChoice = (params) => { | ||
| const skipHandlerResponse = { nodes: [], consumed: 0 }; | ||
| const { nodes, nodeListHandler, parentStyleId, docx } = params; | ||
|
|
||
| if (nodes.length === 0 || nodes[0].name !== 'w:p') { | ||
| return skipHandlerResponse; | ||
| } | ||
|
|
||
| const mainNode = nodes[0]; | ||
| const node = mainNode?.elements?.find((el) => el.name === 'w:r'); | ||
| const hasAltChoice = node?.elements?.some((el) => el.name === 'mc:AlternateContent'); | ||
|
|
||
| if (!hasAltChoice) { | ||
| return skipHandlerResponse; | ||
| } | ||
|
|
||
| const altChoiceNode = node.elements.find((el) => el.name === 'mc:AlternateContent'); | ||
| const altChoiceNodeIndex = node.elements.findIndex((el) => el.name === 'mc:AlternateContent'); | ||
| const allowedNamespaces = ['wps', 'wp14', 'w14', 'w15']; | ||
|
|
||
| const wpsNode = altChoiceNode.elements.find( | ||
| (el) => el.name === 'mc:Choice' && allowedNamespaces.includes(el.attributes['Requires']) | ||
| ); | ||
|
|
||
| if (!wpsNode) { | ||
| return skipHandlerResponse; | ||
| } | ||
|
|
||
| const contents = wpsNode.elements; | ||
| const result = nodeListHandler.handler({ | ||
| ...params, | ||
| nodes: contents, | ||
| }); | ||
|
|
||
| return { nodes: result, consumed: 1 }; | ||
| }; | ||
|
|
||
| /** | ||
| * @type {import("docxImporter").NodeHandlerEntry} | ||
| */ | ||
| export const alternateChoiceHandler = { | ||
| handlerName: 'alternateChoiceHandler', | ||
| handler: handleAlternateChoice, | ||
| }; |
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
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
71 changes: 71 additions & 0 deletions
71
packages/super-editor/src/extensions/content-block/content-block.js
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,71 @@ | ||
| import { Node, Attribute } from '@core/index.js'; | ||
|
|
||
| export const ContentBlock = Node.create({ | ||
| name: 'contentBlock', | ||
|
|
||
| group: 'block', | ||
|
|
||
| content: '', | ||
|
|
||
| isolating: true, | ||
|
|
||
| addOptions() { | ||
| return { | ||
| htmlAttributes: { | ||
| contenteditable: false, | ||
| }, | ||
| }; | ||
| }, | ||
|
|
||
| addAttributes() { | ||
| return { | ||
| size: { | ||
| default: null, | ||
| renderDOM: ({ size }) => { | ||
| if (!size) return {}; | ||
|
|
||
| let style = ''; | ||
| if (size.top) style += `top: ${size.top}px; `; | ||
| if (size.left) style += `left: ${size.left}px; `; | ||
| if (size.width) style += `width: ${size.width}px; `; | ||
| if (size.height) style += `height: ${size.height}px; `; | ||
| return { style }; | ||
| }, | ||
| }, | ||
|
|
||
| background: { | ||
| default: null, | ||
| renderDOM: (attrs) => { | ||
| if (!attrs.background) return {}; | ||
| return { | ||
| style: `background-color: ${attrs.background}`, | ||
| }; | ||
| }, | ||
| }, | ||
|
|
||
| drawingContent: { | ||
| rendered: false, | ||
| }, | ||
|
|
||
| attributes: { | ||
| rendered: false, | ||
| }, | ||
| }; | ||
| }, | ||
|
|
||
| parseDOM() { | ||
| return [ | ||
| { | ||
| tag: `div[data-type="${this.name}"]`, | ||
| } | ||
| ]; | ||
| }, | ||
|
|
||
| renderDOM({ htmlAttributes }) { | ||
| return [ | ||
| 'div', | ||
| Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes, { 'data-type': this.name }), | ||
| 0, | ||
| ]; | ||
| }, | ||
| }); |
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 @@ | ||
| export * from './content-block.js'; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_positioned_layout/Stacking_context
To make
z-index: -1work for the element. This is probably a safer way than assigning z-index to the editor.