{"id":15102010,"url":"https://github.com/rozek/reactive-scriptable-components","last_synced_at":"2026-01-18T17:32:37.028Z","repository":{"id":217292227,"uuid":"743498832","full_name":"rozek/reactive-scriptable-components","owner":"rozek","description":"light-weight reactive scriptable web components","archived":false,"fork":false,"pushed_at":"2024-02-16T08:17:23.000Z","size":4244,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T18:40:54.741Z","etag":null,"topics":["custom-elements","htm","hyperactiv","preact","reactive","scriptable","web-components"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rozek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-15T11:18:27.000Z","updated_at":"2024-02-07T07:21:19.000Z","dependencies_parsed_at":"2025-02-10T22:33:07.532Z","dependency_job_id":"277e6a9f-11cd-48eb-b36c-0e958fae752b","html_url":"https://github.com/rozek/reactive-scriptable-components","commit_stats":null,"previous_names":["rozek/reactive-scriptable-components"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rozek/reactive-scriptable-components","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Freactive-scriptable-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Freactive-scriptable-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Freactive-scriptable-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Freactive-scriptable-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rozek","download_url":"https://codeload.github.com/rozek/reactive-scriptable-components/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Freactive-scriptable-components/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28544787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-elements","htm","hyperactiv","preact","reactive","scriptable","web-components"],"created_at":"2024-09-25T18:44:56.932Z","updated_at":"2026-01-18T17:32:37.009Z","avatar_url":"https://github.com/rozek.png","language":"TypeScript","readme":"# reactive-scriptable-components (RSC) #\n\nlight-weight reactive scriptable web components\n\n\u003e **Warning**: this framework is currently under active development - consider it as incomplete pre-alpha software: anything may change, some changes _may_ even break existing applications (although I don't _expect_ many of them). **Thus, please stay tuned and come back here from time to time to see if there is a (well-documented) version that you may safely use...**\n\nThe idea behind this framework is to allow for the rapid development of small reactive web applications. To give you an idea of what these web apps could look like, consider the following example (which implements a simple calculator that converts temperatures between °Celsius and °Fahrenheit, see [live demo](https://rozek.github.io/reactive-scriptable-components/examples/Temperature-Converter.html)):\n\n![Screenshot of the Temperature Converter Example](TemperatureConverter-Screenshot.png)\n\n```html\n  \u003crsc-applet\u003e\n   \u003crsc-title\u003eTemperature Converter\u003c/rsc-title\u003e\n   \u003crsc-tabular columns=\"2\"\u003e\n    \u003crsc-label\u003e°Celsius:\u003c/rsc-label\u003e\n    \u003crsc-native-number-input $$value=\"Applet:observed.Celsius\"\u003e\u003c/rsc-native-number-input\u003e\n\n    \u003crsc-label\u003e°Fahrenheit:\u003c/rsc-label\u003e\n    \u003crsc-native-number-input $$value=\"Applet:observed.Fahrenheit\"\u003e\u003c/rsc-native-number-input\u003e\n   \u003c/rsc-tabular\u003e\n\n   \u003cscript type=\"rsc-script\"\u003e\n    const observed = Object.assign(this.observed,{\n      Celsius:0,\n      Fahrenheit:0\n    })\n\n    reactively(() =\u003e observed.Fahrenheit = observed.Celsius * 9/5 + 32)\n    reactively(() =\u003e observed.Celsius = 5/9 * (observed.Fahrenheit-32))\n   \u003c/script\u003e\n  \u003c/rsc-applet\u003e\n```\n\nThe example basically consists of two number input controls, a bit of visual \"decoration\" and some \"business logic\".\n\nWhat makes it interesting is how the logic works:\n\n* `$$value` attributes make the number input controls \"reactive\" (in both directions), i.e., user input changes the specified variable and variable changes will be reflected in the UI - and, yes, the circularity of the dependencies shown above causes no problem\n* every \"reactive scriptable component\" (which is a standard [web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)) may contain its own `observed` and `unobserved` (state) variables - in this trivial example, only the applet itself provides some \"state\", whereas the input controls do not\n* whenever an `observed` variable is changed, all functions using that variable may be `reactively` recalculated - in this example, changes of the `Celsius` variable will recompute the `Fahrenheit` variable and vice-versa - and the `$value` reactivity will automatically update the number input fields.\n\nThis approach allows to write simple web applications within minutes - the author uses it for his computer science lectures at [Stuttgart University of Applied Sciences](https://www.hft-stuttgart.com/) in order to demonstrate various concepts and algorithms or give students the possibility to practice what they learned. You probably won't use \"reactive-scriptable-components\" to implement the next office package, but simple tools can be written with very little effort and in a way that may easily be understood even by inexperienced or casual programmers.\n\n**NPM users**: please consider the [Github README](https://github.com/rozek/reactive-scriptable-components) for the latest description of this package (as updating the docs would otherwise always require a new NPM package version)\n\n\u003e Just a small note: if you like this module and plan to use it, consider \"starring\" this repository (you will find the \"Star\" button on the top right of this page), so that I know which of my repositories to take most care of.\n\n## Features ##\n\n\"reactive-scriptable-components\" offer the following fundamental features:\n\n- **Script Attributes**\u003cbr\u003e(small) scripts may be directly provided as an HTML attribute of a component - this keeps a component and it's functionality together\n- **Script Elements**\u003cbr\u003e(larger) scripts may be provided as a `\u003cscript type=\"rsc-script\"/\u003e` element within the component they belong to - e.g., below all other inner HTML elements. This approach keeps the internal structure of an RSC component visible and still allows a component and its code to be kept close together\n- **Delegated Scripts**\u003cbr\u003eif you want to separate the \"look\" from its \"feel\", you may provide \"delegated scripts\" (`\u003cscript type=\"rsc-script\" for=\"...\"/\u003e`) for components that can be identified by a CSS selector (e.g., `#id`, `.class`, `[attr=\"value\"]` etc.)\n- **Behaviour Scripts**\u003cbr\u003eif you have multiple RSC components that share the same functionality, you may define a \"behaviour\" and provide the shared code in a separate `\u003cscript type=\"rsc-script\" for-behaviour=\"...\"/\u003e` element. If there are both a behaviour and a component script for a given RSC component, the behaviour script is executed before the component script.\n- **Observed and Unobserved Variables**\u003cbr\u003eRSC components usually have to store some values they need for their operation. For that purpose, RSC provides both an `observed` and an `unobserved` data structure for every component which can be freely used as required. \"Observed\" entries may then be used to trigger \"reactive functions\" or update \"reactive attributes\" whenever their values change\n- **Reactive Functions**\u003cbr\u003e\"reactive functions\" (defined using `reactively(() =\u003e ...)`) are functions that will be automatically invoked whenever any of the observed(!) values they use internally have changed\n- **Reactive Attributes**\u003cbr\u003e\"reactive attributes\" have names starting with one or two dollar signs (e.g., `$value` or `$$value`) and establish a \"reactive binding\" between a reactive variable of the component itself (`observed.value` in this example) and another reactive variable in an outer RSC component - both a reference to that outer component and the path to the other reactive variable have to be specified in the attribute itself\n- **Event Handlers as Function Calls**\u003cbr\u003esometimes, RSC components do not directly change other (reactive) variables but initiate an activity - to support such use cases, RSC components may trigger events or handle them. In contrast to DOM events, however, RSC events may be used like function calls, i.e., it is allowed to provide arbitrary arguments and possible to wait for a result from event handling\n- **Error Indicators**\u003cbr\u003eoften, it is difficult to recognize and track errors which occured in behaviour or component scripts, or during event handling. For that reason, RSC marks faulty components with an \"error indicator\": just click on such an indicator to reveal details about the detected error\n\n## Built-in Controls ##\n\n![Screenshot of built-in native HTML Controls](nativeControls-Screenshot.png)\n\n## Browser Requirements (and Polyfills) ##\n\nRSC is based on relatively modern web technologies which _should_ already be available in most browsers out-of-the-box - but for those that lack these features (particularily Safari versions \u003c 16.4 or devices with iOS versions \u003c 16.4), polyfills have been included in the examples to plug these holes:\n\n- [Import Maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) (see [availability across browsers](https://caniuse.com/mdn-html_elements_script_type_importmap))\u003cbr\u003efor a polyfill see [https://github.com/guybedford/es-module-shims](https://github.com/guybedford/es-module-shims)\n- [Custom Elements v1](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) (see [availability across browsers](https://caniuse.com/?search=Custom%20Elements))\u003cbr\u003efor a polyfill see [https://github.com/webcomponents/webcomponentsjs](https://github.com/webcomponents/webcomponentsjs)\n\n## Inlined Dependencies ##\n\n\"reactive-scriptable-components\" are based on the following (brilliant!) libraries and packages:\n\n* [HTM (Hyperscript Tagged Markup)](https://github.com/developit/htm) - for easy HTML markup using JavaScript template strings,\n* [PREACT](https://github.com/preactjs/preact) - from which its efficient and light-weight DOM diffing is used, and\n* [Hyperactiv](https://github.com/elbywan/hyperactiv) - a light-weight reactive library which even handles circular dependencies\n\nAll these dependencies have been bundled into a single module for faster loading and a predictable user experience.\n\n\u003e Nota bene: while it may be advisable to [know how to use HTM](https://github.com/developit/htm?tab=readme-ov-file#syntax-like-jsx-but-also-lit), there is no immediate need to learn any of the above to write an RSC application.\n\nThe final distributables were built using the marvellous [microbundle](https://github.com/developit/microbundle).\n\n## Installation ##\n\nIn order to avoid initial flashing of \"custom Elements\" (aka \"Web Components\") you should always add the following lines at the beginning of the `\u003chead/\u003e` section in your HTML file:\n\n```html\n\u003cstyle\u003e\n  :not(:defined) { visibility:hidden }\n\u003c/style\u003e\n```\n\nThis trick applies to all kinds of Web Components, not just those presented here.\n\nMost modern browsers already support import maps and web components out-of-the-box - except Safari browsers \u003c 16.4 or (any browsers on) devices with iOS \u003c 16.4. If you need to support these browsers as well, you should add the following lines directly after the `\u003cstyle/\u003e` section mentioned above:\n\n```html\n \u003c!-- Import Map Polyfill from https://github.com/guybedford/es-module-shims --\u003e\n \u003cscript src=\"https://rozek.github.io/reactive-scriptable-components/polyfills/es-module-shims.js\"\u003e\u003c/script\u003e\n \u003c!-- Web Components Polyfill from https://github.com/webcomponents/webcomponentsjs --\u003e\n \u003cscript src=\"https://rozek.github.io/reactive-scriptable-components/polyfills/webcomponents-bundle.js\"\u003e\u003c/script\u003e\n```\n\n### Using RSC in a \"No-Build Environment\" (e.g., directly in the Browser) ###\n\nIf you don't use any kind of build tool but create your web application directly in the browser or in an HTML file, you should first provide an \"import map\" that allows scripts to import modules by name rather than by URL. Just append the following lines to the `\u003chead/\u003e` section of your HTML file:\n\n```html\n\u003cscript type=\"importmap\"\u003e\n{\n  \"imports\": {\n    \"reactive-scriptable-components\": \"https://rozek.github.io/reactive-scriptable-components/dist/reactive-scriptable-components.modern.js\",\n    \"RSC\":                            \"https://rozek.github.io/reactive-scriptable-components/dist/reactive-scriptable-components.modern.js\"\n  }\n}\n\u003c/script\u003e\n```\n\nThen, if you don't use any package that already _imports_ the RSC module, _load_ it with the following lines:\n\n```html\n\u003cscript type=\"module\"\n src=\"https://rozek.github.io/reactive-scriptable-components/dist/reactive-scriptable-components.modern.js\"\n\u003e\u003c/script\u003e\n```\n\nOtherwise, just _load your package_, e.g. the `full-bundle` with all predefined RSC behaviours:\n\n```html\n \u003cscript type=\"module\"\n  src=\"https://rozek.github.io/reactive-scriptable-components/behaviours/full-bundle.js\"\n \u003e\u003c/script\u003e\n```\n\n### Using RSC with a Module Bundler ###\n\n(t.b.w)\n\n## Applet Creation ##\n\n(t.b.w)\n\n### Component Usage ###\n\n(t.b.w) (lifecycle handling, nesting, containment validation)\n\n### Additional Element Properties and Methods ###\n\nCompared to standard HTML elements, RSC components provide a few additional properties and methods which simplify behaviour and component scripts:\n\n- **`Applet`**\u003cbr\u003eis a getter which returns a reference to the closest visual of `this` one with behaviour \"Applet\"\n- **`Card`**\u003cbr\u003eis a getter which returns a reference to the closest visual of `this` one with behaviour \"Card\"\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`outerVisual`**\u003cbr\u003eis a getter which returns a reference to the next outer visual of `this` one\n- **`outermostVisual`**\u003cbr\u003eis a getter which returns a reference to the outermost visual of `this` one\n- **`closestVisualWithBehaviour (BehaviourName)`**\u003cbr\u003ereturns a reference to the closest visual of `this` one with the given `BehaviourName` - please note, that the \"closest\" may also be `this` visual\n- **`closestOuterVisualWithBehaviour (BehaviourName)`**\u003cbr\u003ereturns a reference to the closest _outer_ visual of `this` one with the given `BehaviourName`\n- **`closestVisualMatching (Selector)`**\u003cbr\u003ereturns a reference to the closest visual of `this` one matching the given `Selector` - please note, that the \"closest\" may also be `this` visual\n- **`closestOuterVisualMatching (Selector)`**\u003cbr\u003ereturns a reference to the closest _outer_ visual of `this` one matching the given `Selector`\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`innerVisuals`**\u003cbr\u003eis a getter which returns a (possibly empty) list of all visuals which are direct children of `this` one\n- **`innerVisualsWithBehaviour (BehaviourName)`**\u003cbr\u003ereturns a (possibly empty) list of all visuals with the given `BehaviourName` which are direct children of `this` one\n- **`innerVisualsMatching (Selector)`**\u003cbr\u003ereturns a (possibly empty) list of all visuals which are direct children of `this` one and match the given `Selector`\n- **`innerElements`**\u003cbr\u003eis a getter which returns a (possibly empty) list of all elements (i.e., not only RSC components) which are direct children of `this` one\n- **`innerElementsMatching (Selector)`**\u003cbr\u003ereturns a (possibly empty) list of all elements (i.e., not only RSC components) which are direct children of `this` one and match the given `Selector`\n\n### Component Scripts ###\n\n(t.b.w) (script as function bodies, script attributes, script elements, delegated scripts)\n\n```javascript\nfunction (\n  my,me, RSC,JIL, onAttributeChange, onAttachment,onDetachment,\n  toRender, html, on,once,off,trigger, reactively\n) {\n// this is where scripts are inserted\n}\n```\n\n- **`my`**\u003cbr\u003econtains a reference to `this` visual (i.e., the one in whose context the current script is running). If you define getters and setters for observed and unobserved variables, inside these accessors, `this` will refer to the data structure rather than to the visual - in such situations, `my` will help you refering to the actual visual. Additionally, you may use `my` to let your code look like ordinary english: e.g., `my.observed.Value = ...`\n- **`me`**\u003cbr\u003eis just a synonym for `my` and may be used wherever the resulting code will then read more like ordinary english: e.g., like in `my.render.bind(me)`\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`RSC`**\u003cbr\u003econtains a reference to RSC itself - thus, if you want to use any of its exported functions, you don't have to import the module yourself in your behaviour or component scripts\n- **`JIL`**\u003cbr\u003esince RSC uses the [javascript-interface-library](https://github.com/rozek/javascript-interface-library) internally anyway, you may use this reference to that library in order to avoid having to import it in your scripts yourself in your behaviour or component scripts\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`onAttributeChange`**\u003cbr\u003e`onAttributeChange((normalizedName,newValue) =\u003e ...)` can be used to install a function (with the given signature) that will be called whenever an attribute of an RSC component was changed. Only one callback function can be installed, later invocations of `onAttributeChange` overwrite previously registered callbacks\n- **`onAttachment`**\u003cbr\u003e`onAttachment(() =\u003e ...)` can be used to install a function that will be called whenever an RSC component is added to the DOM while RSC is running (and all behaviours have already been defined). Only one callback function can be installed, later invocations of `onAttachment` overwrite previously registered callbacks\n- **`onDetachment`**\u003cbr\u003e`onDetachment(() =\u003e ...)` can be used to install a function that will be called whenever an RSC component is removed from the DOM. Only one callback function can be installed, later invocations of `onDetachment` overwrite previously registered callbacks\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`toRender`**\u003cbr\u003e`toRender(() =\u003e ...)` can be used to install a function that will be called whenever an RSC component has to be (re-)rendered. Only one callback function can be installed, later invocations of `toRender` overwrite previously registered callbacks\n- **`html`**\u003cbr\u003eis a reference to the [htm markup function](https://github.com/rozek/htm#--htm-hyperscript-tagged-markup--) prepared for being used with [preact](https://github.com/preactjs/preact) - i.e., within RSC scripts\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`on`**\u003cbr\u003e`on(events, selectors, data, (Event) =\u003e ...)` can be used to install a handler for the given (comma-separated) list of `events`, sent from RSC components or DOM elements identified by any of the (optionally) given (comma-separated) selectors ...\n- **`once`**\u003cbr\u003e\n- **`off`**\u003cbr\u003e\n- **`trigger`**\u003cbr\u003e\u003cbr\u003e\u0026nbsp;\u003cbr\u003e\n- **`reactively`**\u003cbr\u003e`reactively(() =\u003e ...)`\n\n### Behaviour Scripts ###\n\n(t.b.w) (behaviour registry, behaviour definition, behaviour and component scripts together)\n\n### Observed and Unobserved Variables ###\n\n(t.b.w) (accessors, scope)\n\n### Reactive Functions ###\n\n(t.b.w) (reactively, initial invocation, variable tracking, see hyperactiv)\n\n### Reactive Attributes ###\n\n(t.b.w) (access path, unidirectional/bidirectional binding)\n\n### Rendering ###\n\n(t.b.w) (see htm, DOM diffing by preact, initial rendering, automatic vs. manual re-rendering)\n\n### RSC Events ###\n\n(t.b.w) (event handler registration on/once/off, selectors, event triggering, arguments, results, bubbling)\n\n### Error Indicators ###\n\n(t.b.w)\n\n## Pre-defined Behaviours ##\n\n(t.b.w) (full-bundle)\n\n### Basic Components ###\n\n(t.b.w)\n\n### Layout Components ###\n\n(t.b.w)\n\n### Native HTML Controls ###\n\n(t.b.w)\n\n### Various Other Components ###\n\n(t.b.w)\n\n## Examples ##\n\n(t.b.w)\n\n## API Reference ##\n\n(t.b.w)\n\n* **`assign`** \u003cbr\u003e\n* **`isRunning ():boolean`** \u003cbr\u003e\n* **`ValueIsDOMElement (Value:any):boolean`** \u003cbr\u003e\n* **`allow/expect[ed]DOMElement (Description:string, Argument:any):Element|null|undefined`** \u003cbr\u003e\n* **`ValueIsVisual (Value:any):boolean`** \u003cbr\u003e\n* **`allow/expect[ed]Visual (Description:string, Argument:any):RSC_Visual|null|undefined`** \u003cbr\u003e\n* **`ValueIsName (Value:any):boolean`** \u003cbr\u003e\n* **`allow/expect[ed]dName (Description:string, Argument:any):RSC_Name|null|undefined`** \u003cbr\u003e\n* **`ValueIsErrorInfo (Value:any):boolean`** \u003cbr\u003e\n* **`allow/expect[ed]ErrorInfo (Description:string, Argument:any):RSC_ErrorInfo|null|undefined`** \u003cbr\u003e\n* **`newUUID ():RSC_UUID`** \u003cbr\u003e\n* **`outerVisualOf (DOMElement:HTMLElement):RSC_Visual|undefined`** \u003cbr\u003e\n* **`VisualContaining (DOMElement:HTMLElement):RSC_Visual|undefined`** \u003cbr\u003e\n* **`outermostVisualOf (DOMElement:HTMLElement):RSC_Visual|undefined`** \u003cbr\u003e\n* **`closestVisualWithBehaviour(DOMElement:HTMLElement, BehaviourName:RSC_Name):RSC_Visual|undefined`** \u003cbr\u003e\n* **`closestVisualMatchingclosestVisualMatching (DOMElement:HTMLElement, Selector:Textline):RSC_Visual|undefined`** \u003cbr\u003e\n* **`innerVisualsOf (DOMElement:HTMLElement):RSC_Visual[]`** \u003cbr\u003e\n* **`registerBehaviour(Name:RSC_Name, SourceOrExecutable:Text|Function|undefined, observedAttributes:RSC_Name[] = []):void`** \u003cbr\u003e\n\n### Global Reactivity ###\n\n(t.b.w)\n\n* **`observed`** \u003cbr\u003e\n* **`unobserved`** \u003cbr\u003e\n\n### Convenience Functions for Behaviour (and Visual) Scripts ###\n\n(t.b.w)\n\n* **`throwReadOnlyError (Name:string):never`**\u003cbr\u003ethrows an error which indicates that the property called `Name` can not be modified\n\u0026nbsp;\u003cbr\u003e\n* **`BooleanProperty(my:RSC_Visual, PropertyName:string, Default?:boolean, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`BooleanListProperty(my:RSC_Visual, PropertyName:string, Default?:boolean[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`NumberProperty(my:RSC_Visual, PropertyName:string, Default?:number, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`NumberListProperty(my:RSC_Visual, PropertyName:string, Default?:number[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`NumberPropertyInRange(my:RSC_Visual, PropertyName:string, lowerLimit?:number, upperLimit?:number, withLower:boolean = false, withUpper:boolean = false, Default?:number, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`NumberListPropertyInRange(my:RSC_Visual, PropertyName:string, lowerLimit?:number, upperLimit?:number, withLower:boolean = false, withUpper:boolean = false, Default?:number[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`IntegerProperty(my:RSC_Visual, PropertyName:string, Default?:number, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`IntegerListProperty(my:RSC_Visual, PropertyName:string, Default?:number[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`IntegerPropertyInRange(my:RSC_Visual, PropertyName:string, lowerLimit?:number, upperLimit?:number, Default?:number, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`IntegerListPropertyInRange(my:RSC_Visual, PropertyName:string, lowerLimit?:number, upperLimit?:number, Default?:number[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`StringProperty(my:RSC_Visual, PropertyName:string, Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`StringListProperty(my:RSC_Visual, PropertyName:string, Default?:string[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`StringPropertyMatching(my:RSC_Visual, PropertyName:string, Pattern:RegExp, Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`StringListPropertyMatching(my:RSC_Visual, PropertyName:string, Pattern:RegExp, Default?:string[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`TextProperty(my:RSC_Visual, PropertyName:string, Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`TextlineProperty(my:RSC_Visual, PropertyName:string, Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`OneOfProperty(my:RSC_Visual, PropertyName:string, allowedValues:string[], Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`OneOfListProperty(my:RSC_Visual, PropertyName:string, allowedValues:string[], Default?:string[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`URLProperty(my:RSC_Visual, PropertyName:string, Default?:string, Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n* **`URLListProperty(my:RSC_Visual, PropertyName:string, Default?:string[], Description?:string, readonly:boolean = false):object`** \u003cbr\u003e\n\u0026nbsp;\u003cbr\u003e\n* **`handleBooleanAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleBooleanListAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleNumericAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleNumericListAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleLiteralAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleLiteralListAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleLiteralLinesAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleSettingOrKeywordAttribute (reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, permittedValues:string[], permittedKeywords?:string[], PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleJSONAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n* **`handleJSONLinesAttribute(reportedName:string, reportedValue:string|undefined, my:RSC_Visual, Name:string, PropertyName?:string):boolean`** \u003cbr\u003e\n\n## Script Templates ##\n\nThe following code templates may be quite practical when writing custom behaviours - you don't _have_ to use them, but they may save you some typing.\n\n### Initialization ###\n\nExplicitly setting the initial state (and using accessors for any further state changes, as shown below) makes code that uses this state leaner. You may use\n\n```javascript\n  this.unobserved.XXX = ...\n```\n\nif you have a single state variable only, or\n\n```javascript\n  Object.assign(this.unobserved,{\n    XXX:...,\n    YYY:...,\n    ... // add as many variables as you need\n  })\n```\n\nif you have more of them.\n\n### State Access ###\n\nIt is always a good idea to protect a visual's state against faulty values. You may use the following template to define your own custom accessors:\n\n```javascript\n  const my = this       // \"my\" is relevant in the following getters and setters\n  Object.assign(my.observed,{\n    get XXX () { return my.unobserved.XXX },\n    set XXX (newValue) {\n      ... // add your validation logic here\n      my.unobserved.XXX = newValue\n    },\n    ... // add as many accessors as you need\n  })\n```\n\n### Attribute Mapping ###\n\nInternally, RSC works with arbitrary JavaScript values as their state, but initially, you may want to configure your components using element attributes (which are always strings). You may use the following code to map attributes to state variables\n\n```javascript\n  onAttributeChange((Name, newValue) =\u003e {\n    if (Name === 'xxx') {\n      this.observed.XXX = newValue\n      return true\n    }\n  }) // not returning \"true\" triggers automatic mapping\n```\n\nif you only need to map a single attribute, or\n\n```javascript\n  onAttributeChange((Name, newValue) =\u003e {\n    switch (Name) {\n      case 'xxx': this.observed.XXX = newValue; break\n      case 'yyy': this.observed.YYY = newValue; break\n      ... // add as many mappings as you need\n      default: return false // triggers automatic mapping\n    }\n    return true\n  })\n```\n\nif you want to map more of them.\n\nPlease, keep in mind, that you may have to _parse_ given attributes before they can be assigned to state variables. Typical \"parsers\" include:\n\n```javascript\n  parseFloat(newValue)\n  parseInt(newValue,10)\n  JSON.parse(newValue)\n```\n\nDon't forget, that parsing may fail - you may want to handle parser errors explicitly, but RSC will catch exceptions in `onAttributeChange` and present an error indicator for any unhandled error.\n\n\u003e **Important**: don't forget to add all relevant attribute names to the `observed-attributes` attribute of your behaviour script element\n\u003e \n\u003e \u0026nbsp; `\u003cscript type=\"rsc-script\" for-behaviour=\"...\" observed-attributes=\"xxx, yyy, ...\"\u003e`\n\u003e \n\u003e or `onAttributeChange` will never be invoked.\n\n\u003e Nota bene: if internal names and attribute names of all variables are the same (except for capitalisation) and you also do not have to parse any of the attributes (e.g., because all variables are of type `string` anyway), then there is no need for an explicit `onAttributeChange` handler: RSC will map such attributes automatically.\n\n### Custom Rendering ###\n\nIn almost any case, you may want to render your new visual in a custom way: use\n\n```javascript\n  toRender(() =\u003e html`...`)\n```\n\nfor simple one-liners without additional rendering logic, or\n\n```javascript\n  toRender(() =\u003e {\n    ... // add your logic here\n    return html`...`\n  })\n```\n\nfor anything else.\n\n### Complete (Behaviour) Script Template ###\n\nJust for the sake of convenience, here is the complete template for a behaviour script\n\n```html\n\u003cscript type=\"rsc-script\" for-behaviour=\"...\" observed-attributes=\"xxx, yyy, ...\"\u003e\n  Object.assign(this.unobserved,{\n    XXX:...,\n    YYY:...,\n    ... // add as many variables as you need\n  })\n\n  const my = this       // \"my\" is relevant in the following getters and setters\n  Object.assign(my.observed,{\n    get XXX () { return my.unobserved.XXX },\n    set XXX (newValue) {\n      ... // add your validation logic here\n      my.unobserved.XXX = newValue\n    },\n    ... // add as many accessors as you need\n  })\n\n  onAttributeChange((Name, newValue) =\u003e {\n    switch (Name) {\n      case 'xxx': this.observed.XXX = newValue; break\n      case 'yyy': this.observed.YYY = newValue; break\n      ... // add as many mappings as you need\n      default: return false // triggers automatic mapping\n    }\n    return true\n  })\n\n  toRender(() =\u003e {\n    const { XXX,YYY,... } = this.observed\n\n    ... // add your logic here\n    return html`...`\n  })\n\u003c/script\u003e\n```\n\nIf you want to create a script element for a specific visual, simply\n\n* remove `for-behaviour=\"...\"` (or replace it by `for=\"...\"` for a delegated script) and\n* remove `observed-attributes=\"...\"`(because only behaviours can observe element attributes)\n\nThat's it!\n\n## Build Instructions ##\n\nYou may easily build this package yourself.\n\nJust install [NPM](https://docs.npmjs.com/) according to the instructions for your platform and follow these steps:\n\n1. either clone this repository using [git](https://git-scm.com/) or [download a ZIP archive](https://github.com/rozek/reactive-scriptable-components/archive/refs/heads/main.zip) with its contents to your disk and unpack it there \n2. open a shell and navigate to the root directory of this repository\n3. run `npm install` in order to install the complete build environment\n4. execute `npm run build` to create a new build\n\nIf you made some changes to the source code, you may also try\n\n```\nnpm run agadoo\n```\n\nin order to check if the result is still tree-shakable.\n\nYou may also look into the author's [build-configuration-study](https://github.com/rozek/build-configuration-study) for a general description of his build environment.\n\n## License ##\n\n[MIT License](LICENSE.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozek%2Freactive-scriptable-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frozek%2Freactive-scriptable-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozek%2Freactive-scriptable-components/lists"}