|
1 | 1 | from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, Union
|
2 | 2 |
|
| 3 | +from fastjsonschema import compile as compile_json_schema |
3 | 4 | from mypy_extensions import TypedDict
|
4 | 5 | from typing_extensions import Protocol
|
5 | 6 |
|
6 | 7 | from .component import AbstractComponent
|
7 | 8 | from .events import EventsMapping
|
8 | 9 |
|
| 10 | +SERIALIZED_VDOM_JSON_SCHEMA = { |
| 11 | + "$schema": "http://json-schema.org/draft-07/schema", |
| 12 | + "$ref": "#/definitions/element", |
| 13 | + "definitions": { |
| 14 | + "element": { |
| 15 | + "type": "object", |
| 16 | + "properties": { |
| 17 | + "tagName": {"type": "string"}, |
| 18 | + "children": {"$ref": "#/definitions/elementChildren"}, |
| 19 | + "attributes": {"type": "object"}, |
| 20 | + "eventHandlers": {"$ref": "#/definitions/elementEventHandlers"}, |
| 21 | + "importSource": {"$ref": "#/definitions/importSource"}, |
| 22 | + }, |
| 23 | + "required": ["tagName"], |
| 24 | + }, |
| 25 | + "elementChildren": { |
| 26 | + "type": "array", |
| 27 | + "items": {"$ref": "#/definitions/elementOrString"}, |
| 28 | + }, |
| 29 | + "elementEventHandlers": { |
| 30 | + "type": "object", |
| 31 | + "patternProperties": { |
| 32 | + ".*": {"$ref": "#/definitions/eventHander"}, |
| 33 | + }, |
| 34 | + }, |
| 35 | + "eventHander": { |
| 36 | + "type": "object", |
| 37 | + "properties": { |
| 38 | + "target": {"type": "string"}, |
| 39 | + "preventDefault": {"type": "boolean"}, |
| 40 | + "stopPropagation": {"type": "boolean"}, |
| 41 | + }, |
| 42 | + "required": ["target"], |
| 43 | + }, |
| 44 | + "importSource": { |
| 45 | + "type": "object", |
| 46 | + "properties": { |
| 47 | + "source": {"type": "string"}, |
| 48 | + "fallback": { |
| 49 | + "if": {"not": {"type": "null"}}, |
| 50 | + "then": {"$ref": "#/definitions/elementOrString"}, |
| 51 | + }, |
| 52 | + }, |
| 53 | + "required": ["source"], |
| 54 | + }, |
| 55 | + "elementOrString": { |
| 56 | + "if": {"not": {"type": "string"}}, |
| 57 | + "then": {"$ref": "#/definitions/element"}, |
| 58 | + }, |
| 59 | + }, |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +validate_serialized_vdom = compile_json_schema(SERIALIZED_VDOM_JSON_SCHEMA) |
| 64 | + |
9 | 65 |
|
10 | 66 | class ImportSourceDict(TypedDict):
|
11 | 67 | source: str
|
|
0 commit comments