-
Notifications
You must be signed in to change notification settings - Fork 152
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
Atoms #226
Atoms #226
Conversation
* `buffer` is an array passed to the `html` hook instead of a DOM element. | ||
The content for the atom should be pushed on that array as a string. | ||
* `options` is the `cardOptions` argument passed to the editor or renderer. | ||
* `env` contains information about the running of this hook. It may contain |
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.
If a card can remove itself, can it also save itself? It if can trigger its own destruction, it seems reasonable that it could change its payload as well.
On the other hand, part of me thinks it should not be able to remove or edit itself. The most conservative approach is that they can only be created and if they are removed it must be through normal editing operations like backspace and delete. Thoughts?
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.
I took out all the other ones from cards because save/cancel/edit/section didn't seem to be needed for atoms at first glance.
I can picture a use-case for remove
such as showing an x
on hover and letting you click it to remove the atom, but certainly happy to leave that out initially!
If we do have remove, I can think of some use-cases where an atom could be expose an interface which alters it and therefor would want to update its payload. Not something I personally need right now hence why it didn't spring to mind initially.
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.
remove
with an x
implies that the atom is (partially) in charge of its editing interface. I'd prefer to lean on the conservative path for now and ensure they have zero control over their editing interface.
We can revisit as we get more complex use-cases, if that seems reasonable to you as well.
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.
👍
var demoAtom = { | ||
name: 'mention', | ||
display: { | ||
setup(element, options, env, text, payload) { |
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.
I know this is annoying, but let's change this to follow the new card schema as suggested in #228 (comment)
// package: mda-profile-dom
export default {
name: 'profile',
type: 'dom',
render({element, options, env, text, payload}) {
}
};
Looks good to go :-) @rlivsey I presume we will just leave it open while you spike on implementation this week. We should attempt to preserve the 0.2 compatibility as we make changes. It will be a bit more painful in the short term since the versioning of parsers/renderer will need to be implemented, but will allow us to merge patches incrementally. |
} | ||
|
||
remove() { | ||
// this.editor.run(postEditor => postEditor.removeSection(this.model)); |
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.
should likely teardown here
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.
This can just be removed.
This looks good — probably the first set of challenges will be breakage caused by methods in |
Getting close… |
|
||
## Atom format | ||
|
||
An atom is a javascript object with 3 *required* properties: |
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.
"JavaScript" nit pick :-p
Atoms now have ZWNJ's around them, so when in a section on their own the cursor appears correctly. Next up is figuring out that the cursor is directly before/after the atom so we can jump across when hitting left/right. For cards this is easy enough as the whole section is a card and so Detecting if you're next to an atom is a little trickier by the looks of it. The atom's DOM looks like: <span>
ZWNJ
<span class="-mobiledoc-kit__atom">...</span>
ZWNJ
</span> If the cursor is right after the atom, or in the let renderNode = this._renderTree.getElementRenderNode(anchorNode.parentNode);
if (renderNode && renderNode.postNode.isAtom) {
// ...
} If the cursor is directly before the atom however, it's not in the let _comparePosition = comparePosition(this.cursor.selection);
if (_comparePosition.tailNode.length === _comparenPosition.tailOffset) { // at the end of the node
let nextNode = _comparePosition.tailNode.nextElementSibling;
let renderNode = nextNode && this._renderTree.getElementRenderNode(nextNode);
if (renderNode && renderNode.postNode.isAtom) {
// ...
}
} Any thoughts on a nicer way of handling this? |
4b56061
to
d8c53f1
Compare
Change cursor#_findNodeForPosition to target the textnode after an atom's ending zwnj when there is one. Also changes the editor keyDown handler to reposition the cursor onto that next text node. Changes to dom parsing to read text content out of the zwnj on either side of an atom and merge it into the before/after marker (or create new marker(s) to accept that text) Changes lifecycle callbacks #addCallbackOnce method to remove the once-added callback after flushing that queue
* change _findCursorForPosition to focus on atom markers properly * dom parser marks sections dirty when adding a new marker * postEditor#deleteBackwardFrom removes atom marker appropriately
I am finding one outstanding bug that I'm working on fixing:
And have fixed the following bugs that now need test coverage:
|
…Blank usage * add atom#splitAtOffset * remove marker#join * add `canJoin` to atom and marker
Closing in favor of #311 |
Work in progress thoughts on Atoms
Will implement #222
contenteditable
to falseDOMParser
Maybe:
unknownAtomHandler
implementation which just renders the value?