-
Notifications
You must be signed in to change notification settings - Fork 4
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
Text Align Feature #22
Comments
Hello, |
Hi, get run() { get enable() { Instead of wrapIn what exactly should I do? A code suggestion would be of great help |
What you proposed actually. You don't need a wrapper. Add the text-align property to the paragraph. Haven't done it but this makes more sense. So in your config for example |
okay I'll try out these suggestions. |
Hi, Uncaught Error: NodeType.create can't construct text nodes |
right is not applicable there. Use Commands from wax-prosemirror-core Commands.setBlockType(state.config.schema.nodes.paragraph, { |
This did not work. The second problem is that if I want to align another tag like h2, or a list, then this approach would be very difficult. There should be some way to just edit or update the style attribute of the node. |
Currently, the following implementation works but it works only for paragraphs. So need to come up with a different logic to handle alignment for all tags. //RightAlignService.js
// rightAlignNode.js
//RightAlign.js
|
@christos8333 finally got the text-align feature to work. This is my implementation To perform center alignment:
CenterAlign.js
and finally setAttr function inside Commands.js
Add the style attribute to all the tags in the schema like below:
The final part is to integrate it with track changes. Any suggestions? |
Hi,
Recently I tried building the text-align feature in the Wax editor but there were some problems with my implementation.
The main problem with my approach is that the contents get aligned by wrapping it with a div element with a style attribute. But it would be a lot better if I could just update or add a style attribute to the current node.
Is there a way to resolve this issue?
This is how I implemented the service:
//rightAlignService.js
import { Service } from 'wax-prosemirror-core';
import rightAlignNode from '../schema/rightAlignNode';
import RightAlign from './RightAlign';
class RightAlignService extends Service {
register() {
this.container.bind('RightAlign').to(RightAlign);
const createNode = this.container.get('CreateNode');
createNode(
{
rightAlign: rightAlignNode,
},
);
}
}
export default RightAlignService;
//rightAlignNode.js
const rightAlignNode = {
content: 'block*',
group: 'block',
code: true,
defining: true,
// marks: 'comment insertion deletion',
attrs: { params: { default: '' } },
parseDOM: [
{
tag: 'div',
preserveWhitespace: 'full',
getAttrs(dom) {
return {
params: dom.dataset.params,
};
},
},
],
toDOM(node) {
return ['div', { 'style': 'text-align: right' }, 0];
},
};
export default rightAlignNode;
//RightAlign.js
import { injectable } from 'inversify';
import { wrapIn } from 'prosemirror-commands';
import { Tools } from 'wax-prosemirror-core';
@Injectable()
export default class RightAlign extends Tools {
title = 'Right Align';
icon = 'rightAlign';
name = 'rightAlign';
get run() {
return (state, dispatch) => {
wrapIn(state.config.schema.nodes.rightAlign)(state, dispatch);
};
}
select = (state, activeViewId, activeView) => {
const { disallowedTools } = activeView.props;
if (disallowedTools.includes('rightAlign')) return false;
return true;
};
get enable() {
return state => {
return wrapIn(state.config.schema.nodes.rightAlign)(state);
};
}
}
The text was updated successfully, but these errors were encountered: