This document outlines the complete implementation plan for the Microdata API as specified in SCHEMA-API.md. Each task is marked with a checkbox for tracking completion.
- Create MicrodataItem class using ES6 Proxy
- Implement automatic JSON-LD structure (
@type,@context,@id) - Add property getter that reads from DOM elements with matching itemprop
- Add property setter that updates DOM elements with matching itemprop
- Implement itemref resolution within same document
- Add cycle detection for itemref with console.warn
- Handle array properties based on multiple DOM elements
- Extract @type from itemtype URL (last path segment)
- Extract @context from itemtype URL (base URL)
- Generate @id from element id or itemid attribute
- Create MicrodataCollection extending Array
- Implement numeric indexing (
document.microdata[0]) - Implement named access using Proxy (
document.microdata.johndoe) - Override Symbol.iterator for proper iteration
- Implement forEach, map, filter array methods
- Support Object.keys() to list items with IDs
- Filter to only include top-level items (not nested)
- Maintain internal index of items by ID
- Add
microdatagetter to Document.prototype - Add
microdatagetter to Element.prototype for itemscope elements - Create global MutationObserver on document
- Watch for additions/removals of itemscope elements
- Watch for changes to itemprop elements
- Watch for changes to itemtype, itemid, itemref attributes
- Implement immediate DOM updates (no batching)
- Initialize microdata collection on DOMContentLoaded
- Create base Schema class with factory constructor
- Implement async schema fetching in constructor
- Create SchemaOrgSchema subclass
- Create RustyBeamNetSchema subclass
- Implement determineSchemaType() method
- Parse fetched schema content to determine type
- Default to SchemaOrgSchema on fetch error
- Return appropriate subclass instance from constructor
- Create global schema cache Map
- Implement schema URL normalization
- Add cache check before fetching
- Scan document for all itemtype attributes on load
- Fetch all unique schemas in parallel
- Store parsed schemas in cache
- Fire DOMSchemasLoaded event when all complete
- Fire DOMSchemaError event for each failed schema
- Parse schema.org schema format
- Extract property names
- Implement basic property existence validation
- Default all properties to optional (0..n cardinality)
- No value type validation
- Parse rustybeam.net schema format
- Extract property definitions with cardinality
- Extract DataType references
- Implement cardinality validation (1, 1..n, 0..n)
- Fetch and cache referenced DataTypes
- Implement regex pattern validation from DataTypes
- Support nested complex type validation
- Add validate() method to MicrodataItem
- Check property existence against schema
- Validate cardinality constraints
- Validate values against DataType patterns
- Return boolean result immediately (synchronous with loaded check)
- Collect validation errors for debugging
- Support validation without loaded schemas (returns true)
- Fire DOMSchemaInvalidData on property set (during validation)
- Include validation error details in event
- Bubble event from itemprop element to itemscope to document
- Continue DOM update even if validation fails
- Create Template class constructor accepting template element
- Parse template for itemtype attributes
- Extract schemas property listing found types
- Implement validate() method for pre-render validation
- Create render() method accepting data object
- Support rendering plain objects
- Support rendering MicrodataItem instances
- Support rendering form elements
- Support rendering DOM elements/fragments
- Clone template content for rendering
- Find all itemprop elements in template
- Map data properties to itemprop elements
- Handle text content for simple properties
- Handle nested itemscope for complex properties
- Implement array rendering for
itemprop="name[]"syntax - Render single element for single values with array syntax
- Render nothing for missing properties
- Generate unique IDs for cloned elements
- Scan for elements with
data-containsattribute - Extract schema URL from attribute value
- Find template element within container
- Locate all authoritative items (with id) matching schema
- Render template for each authoritative item
- Set itemid on rendered items linking to source
- Watch for new authoritative items via MutationObserver
- Watch for removed authoritative items
- Add/remove rendered items dynamically
- Establish two-way binding between authoritative and rendered items
- Update rendered items when authoritative items change
- Update authoritative items when rendered items change
- Prevent infinite update loops
- Maintain synchronization through MutationObserver
- Create form data extractor (in _extractData methods)
- Map form input name attributes to properties
- Handle text, password, email input types
- Handle select elements
- Handle textarea elements
- Handle checkbox groups for arrays
- Handle radio buttons
- Extract values into plain object
- Extend Schema.validate() to accept form elements
- Extract data from form
- Validate against schema
- Support HTML5 form validation integration
- Return validation result
- Extend Template.render() to accept form elements
- Extract form data
- Render to template
- Maintain form state in rendered output
- Create static fetch method on Microdata class
- Fetch HTML content from URL
- Parse HTML into Document
- Create document-like wrapper object
- Add isolated microdata property
- Support fragment identifiers (#id)
- Extract specific element for fragments
- Return element-like wrapper for fragments
- Parse microdata in fetched document
- Create separate MicrodataCollection
- Ensure no cross-document itemref
- Maintain isolation from main document
- Support microdata operations on fetched content
- Implement DOMSchemasLoaded event
- Fire when all schemas loaded on initial page load
- Include loaded schemas in event detail
- Implement DOMSchemaError event
- Fire for each schema that fails to load
- Include schema URL and error in event detail
- Implement DOMSchemaInvalidData event
- Fire on itemprop element for invalid value
- Bubble to itemscope element
- Bubble to document
- Include validation details in event
- Implement DOMSchemaError on elements
- Fire on itemtype element for schema load failure
- Then fire on document
- Export Microdata as named export
- Export Schema as named export
- Export Template as named export
- Export Microdata as default export
- Set window.Microdata global
- Set window.Microdata.Schema
- Set window.Microdata.Template
- Implement Microdata.fetch() static method
- Implement Template.render() static shorthand
- Add Schema.clearCache() for testing
- Handle missing itemtype gracefully
- Handle malformed schema URLs
- Handle network errors in fetch
- Provide helpful console warnings
- Validate itemref ID existence
- Optimize MutationObserver filters
- Implement efficient DOM queries
- Cache parsed schemas aggressively
- Minimize DOM traversals
- Batch schema fetches
- Ensure Proxy support
- Ensure MutationObserver support
- Test array method inheritance
- Verify event bubbling behavior
- Add any necessary polyfills
- Test MicrodataItem property access
- Test MicrodataCollection dual interface
- Test Schema factory pattern
- Test validation logic
- Test template rendering
- Test event firing
- Test live DOM synchronization
- Test schema loading and caching
- Test template auto-sync
- Test form validation
- Test fetch API
- Test complex itemref scenarios
- Create basic microdata example
- Create complex nested example
- Create template sync example
- Create form validation example
- Create fetch API example
- Update test.html with all examples
- All core functionality implemented
- All events firing correctly
- All edge cases handled
- Performance optimized
- Fully tested
- Examples documented
- Codebase documented
- Codebase meets beautiful code standards in CLAUDE.md
- Ready for production use
- Fully documented explanation of the project and the API in README.md - [x] README.md completely rewritten.