Skip to content

Commit

Permalink
feat(demo): schema validation (#949)
Browse files Browse the repository at this point in the history
Build on previous (#948) refactor to introduce schema validation for
custom elements and behaviors:

- Extend core schema and add boilerplate to allow custom definitions
- Update yarn command to delete generated files before regenerating, and
point to extend schema file

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new XML Schema for filtering functionality, enhancing the
Hyperview framework.
	- Added new types and elements for improved filtering capabilities.
  
- **Changes**
- Updated XML namespace for the filter component to align with the new
Hyperview standards.
	- Modified validation scripts to streamline XML validation processes.
  
These updates enhance the user experience by providing more robust
filtering options and ensuring compatibility with the latest framework
standards.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: flochtililoch <[email protected]>
  • Loading branch information
flochtililoch and flochtililoch authored Oct 1, 2024
1 parent ed3636d commit d36b135
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ hv_title: "Filter"
{% extends 'templates/base.xml.njk' %}

{% block custom_ns %}
xmlns:filter="https://instawork.com/hyperview-filter"
xmlns:filter="https://hyperview.org/filter"
{% endblock %}

{% block styles %}
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"server": "eleventy --serve --port=8085",
"test:lint": "eslint src && prettier --check '**/*.md' && yarn format-njk -c",
"test:ts": "tsc",
"test:validate-xml": "eleventy; find hyperview/public ../test/schema -name '*.xml' -not -path '*/advanced/scroll/*.xml' -not -path '*/case-studies/business-rating/index.xml' -not -path '*/case-studies/business-rating/rating_save.xml' -not -path '*/case-studies/photos/comments.xml' -not -path '*/index.xml' | xargs xmlschema-validate --schema ../schema/hyperview.xsd --version 1.1",
"test:validate-xml": "rm -rf hyperview/public; eleventy; find hyperview/public -name '*.xml' -not -path '*/advanced/scroll/*.xml' -not -path '*/case-studies/business-rating/index.xml' -not -path '*/case-studies/business-rating/rating_save.xml' -not -path '*/case-studies/photos/comments.xml' -not -path '*/index.xml' | xargs xmlschema-validate --schema schema/hyperview.xsd --version 1.1",
"test": "yarn test:ts && yarn test:lint && yarn test:validate-xml"
},
"dependencies": {
Expand Down
41 changes: 41 additions & 0 deletions demo/schema/filter.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="https://hyperview.org/filter"
xmlns:filter="https://hyperview.org/filter"
xmlns:hv="https://hyperview.org/hyperview"
>
<xs:import
namespace="https://hyperview.org/hyperview"
schemaLocation="hyperview.xsd"
/>
<xs:simpleType name="transform">
<xs:restriction base="xs:string">
<xs:enumeration value="lowercase" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="role">
<xs:restriction base="xs:string">
<xs:enumeration value="filter-terms" />
</xs:restriction>
</xs:simpleType>

<xs:element name="container">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="id" type="hv:ID" form="unqualified" />
<xs:attribute name="on-event" type="xs:string" use="required" />
<xs:attribute name="on-param" type="xs:string" use="required" />
<xs:attribute name="transform" type="filter:transform" />
</xs:complexType>
</xs:element>

<xs:attributeGroup name="filterAttributes">
<xs:attribute name="regex" type="xs:string" />
<xs:attribute name="role" type="filter:role" />
<xs:attribute name="terms" type="xs:string" />
</xs:attributeGroup>
</xs:schema>
72 changes: 72 additions & 0 deletions demo/schema/hyperview.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="https://hyperview.org/hyperview"
xmlns:hv="https://hyperview.org/hyperview"
xmlns:alert="https://hyperview.org/hyperview-alert"
>
<xs:import
namespace="https://hyperview.org/hyperview-alert"
schemaLocation="../../schema/alert.xsd"
/>
<xs:import
namespace="https://hyperview.org/filter"
schemaLocation="filter.xsd"
/>

<xs:redefine schemaLocation="../../schema/core.xsd">
<xs:simpleType name="action">
<xs:restriction base="hv:action">
<!-- Hyperview core -->
<xs:enumeration value="push" />
<xs:enumeration value="new" />
<xs:enumeration value="back" />
<xs:enumeration value="close" />
<xs:enumeration value="navigate" />
<xs:enumeration value="reload" />
<xs:enumeration value="deep-link" />
<xs:enumeration value="open-settings" />
<xs:enumeration value="dispatch-event" />
<xs:enumeration value="replace" />
<xs:enumeration value="replace-inner" />
<xs:enumeration value="append" />
<xs:enumeration value="prepend" />
<xs:enumeration value="show" />
<xs:enumeration value="hide" />
<xs:enumeration value="toggle" />
<xs:enumeration value="set-value" />
<xs:enumeration value="alert" />
<xs:enumeration value="select-all" />
<xs:enumeration value="unselect-all" />
<xs:enumeration value="scroll" />

<!-- Hyperview demo extensions -->
<!-- None yet, add future custom behavior actions here -->
</xs:restriction>
</xs:simpleType>

<xs:attributeGroup name="behaviorAttributes">
<!-- Hyperview core -->
<xs:attributeGroup ref="hv:behaviorAttributes" />

<!-- Hyperview demo extensions -->
<!-- None yet, add future custom behavior attributes here -->
</xs:attributeGroup>

<!-- This redefines the behavior element with our custom actions / attributes -->
<xs:complexType name="behavior">
<xs:complexContent>
<xs:restriction base="hv:behavior">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="alert:option" />
<xs:element minOccurs="0" maxOccurs="unbounded" ref="hv:styles" />
</xs:sequence>
<xs:attributeGroup ref="hv:behaviorAttributes" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>

</xs:redefine>
<xs:element name="behavior" type="hv:behavior" />
</xs:schema>
2 changes: 1 addition & 1 deletion demo/src/Components/HyperviewFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type FormDataPart = {
declare class FormData {
getParts(): Array<FormDataPart>;
}
const FILTER_NS = 'https://instawork.com/hyperview-filter';
const FILTER_NS = 'https://hyperview.org/filter';

export const findElements = (node: Element, attributeNames: string[]) => {
if (node.nodeType !== NODE_TYPE.ELEMENT_NODE) {
Expand Down

0 comments on commit d36b135

Please sign in to comment.