-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into typing-2
- Loading branch information
Showing
8 changed files
with
149 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,53 @@ | ||
from typing import Any, Optional | ||
|
||
from prosemirror.model import Node, Schema | ||
from prosemirror.transform.map import Mappable | ||
from prosemirror.utils import JSON, JSONDict | ||
|
||
from .step import Step, StepMap, StepResult, step_json_id | ||
|
||
|
||
class DocAttrStep(Step): | ||
def __init__(self, attr: str, value: JSON): | ||
super().__init__() | ||
self.attr = attr | ||
self.value = value | ||
|
||
def apply(self, doc: Node) -> StepResult: | ||
attrs = {} | ||
for name in doc.attrs: | ||
attrs[name] = doc.attrs[name] | ||
attrs[self.attr] = self.value | ||
updated = doc.type.create(attrs, doc.content, doc.marks) | ||
return StepResult.ok(updated) | ||
|
||
def get_map(self) -> StepMap: | ||
return StepMap.empty | ||
|
||
def invert(self, doc: Node) -> "DocAttrStep": | ||
return DocAttrStep(self.attr, doc.attrs[self.attr]) | ||
|
||
def map(self, mapping: Mappable) -> Optional[Step]: | ||
return self | ||
|
||
def to_json(self) -> JSONDict: | ||
json_data = { | ||
"stepType": "docAttr", | ||
"attr": self.attr, | ||
"value": self.value, | ||
} | ||
|
||
return json_data | ||
|
||
@staticmethod | ||
def from_json(schema: Schema[Any, Any], json_data: JSONDict | str) -> "DocAttrStep": | ||
if isinstance(json_data, str): | ||
import json | ||
|
||
json_data = json.loads(json_data) | ||
if not isinstance(json_data["attr"], str): | ||
raise ValueError("Invalid input for DocAttrStep.from_json") | ||
return DocAttrStep(json_data["attr"], json_data["value"]) | ||
|
||
|
||
step_json_id("docAttr", DocAttrStep) |
This file contains 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "prosemirror" | ||
version = "0.3.5" | ||
version = "0.3.7" | ||
description = "Python implementation of core ProseMirror modules for collaborative editing" | ||
readme = "README.md" | ||
authors = ["Shen Li <[email protected]>"] | ||
|
This file contains 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