I’m having issues setting a timestamp attribute to nodes. Here’s a short snippet in the plugin update method:
// set timestamp if there was a change and no previous timestamp
if (prevState && prevState.doc.eq(state.doc) && !node.attrs.ts) {
node.attrs.ts = new Date().toISOString();
}
The issue is that the ts attribute will be the same for all nodes with type of paragraph, even when creating a new paragraph node. I am not getting this issue with headers of different levels. If I inspect these paragraph nodes, I notice that node.type.defaultAttrs.ts are all set to the same timestamp. I couldn’t find documentation for this property.
Specifying attributes in the schema doesn’t solve this issue:
and it seems to be working! However, I’m still unclear with the correct way of specifying attributes in the schema. I could have sworn I saw an example that had a pattern that looked like:
That looks like the way it was in some pre-1.0 version. Now it’s enough to say attrs: {foo: {default: "bar"}} (see the docs). Don’t monkey-patch .defaultAttrs—that might break in future versions.
Hmmm in that case, maybe I’m still doing something wrong. If I do not include the hasDefault: true attribute, OR if I do not manually add .defaultAttrs the app will crash with this error:
function computeAttrs(attrs, value) {
var built = Object.create(null);
for (var name in attrs) {
var given = value && value[name];
if (given === undefined) {
var attr = attrs[name];
if (attr.hasDefault) {
given = attr.default;
} else {
throw new RangeError("No value supplied for attribute " + name);
}
}
built[name] = given;
}
return built;
}
hasDefault is a property on the internal Attribute type, which you shouldn’t even be touching from user code, so yes, it does look like you’re doing something wrong. How are you creating the Schema object?
which broke a bunch of stuff but I realized the issues were from using defaultMarkdownParser. I’m currently building my own markdown parser and it seems like I’m on the right path. Thanks!!