ObjectVisualElement.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { createBox } from '../../projection/geometry/models.mjs';
  2. import { VisualElement } from '../VisualElement.mjs';
  3. function isObjectKey(key, object) {
  4. return key in object;
  5. }
  6. class ObjectVisualElement extends VisualElement {
  7. constructor() {
  8. super(...arguments);
  9. this.type = "object";
  10. }
  11. readValueFromInstance(instance, key) {
  12. if (isObjectKey(key, instance)) {
  13. const value = instance[key];
  14. if (typeof value === "string" || typeof value === "number") {
  15. return value;
  16. }
  17. }
  18. return undefined;
  19. }
  20. getBaseTargetFromProps() {
  21. return undefined;
  22. }
  23. removeValueFromRenderState(key, renderState) {
  24. delete renderState.output[key];
  25. }
  26. measureInstanceViewportBox() {
  27. return createBox();
  28. }
  29. build(renderState, latestValues) {
  30. Object.assign(renderState.output, latestValues);
  31. }
  32. renderInstance(instance, { output }) {
  33. Object.assign(instance, output);
  34. }
  35. sortInstanceNodePosition() {
  36. return 0;
  37. }
  38. }
  39. export { ObjectVisualElement };