arrmatura 6.2.1 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Arrmatura
2
+
3
+ ## Definitive
4
+
5
+ `Arrmatura` is a framework which inherits declarative approach and functional programming.
6
+
7
+ It comprises of
8
+
9
+ - extended HTML notation to define components, its composition, behaviour and data flow.
10
+ - type system and runtime enabling development of applications of any kind.
11
+ - `IPlatform` implementation for web client applications.
12
+ - Web UI kits with plenty of components, services, forms, editors etc.
13
+
14
+ ## Key features and benefits of the platform
15
+
16
+ The framework is designed to facilitate the creation of web applications
17
+ by allowing developers to define components and specify how they are composed and connected.
18
+
19
+ This component composition is achieved through a declarative syntax,
20
+ which describes how data flows between components and how it is propagated across the composition.
21
+
22
+ This streamlines the development process and makes it easier for developers
23
+ to create complex and dynamic applications that can respond to changes in data in real-time.
24
+
25
+ Overall, the framework aims to provide a flexible and intuitive way
26
+ to build web applications that are scalable, maintainable, and responsive.
27
+
28
+ ## Documentation
29
+
30
+ - [Manual](docs/manual.md)
31
+ - [Glossary](docs/glossary.md)
32
+
33
+ ## Getting started for Web
34
+
35
+ See [Hello, world](docs/HELLO.md) for starting example.
36
+
37
+ ## Examples
38
+
39
+ - [Emoji List](https://emojis-list.web.app/)
40
+ - [Countries List](https://countries-list.web.app/)
41
+ - [Game Solver](https://dlitskevich.github.io/solver/) ([source](https://github.com/dlitskevich/solver/tree/master/app))
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{CRootNode as m}from"./src/registry/root";export*from"./src/registry";import{CRootNode as c}from"./src/registry/root";export*from"./src/core/Component";var n=(o,t)=>{let r=new m(t).createArrmatron(o);return r.up({},!0),r};export{c as CRootNode,n as launch};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../index.ts"],
4
+ "sourcesContent": ["import { IArrmatron, IPlatform } from \"arrmatura/types\";\n\nimport { CRootNode } from \"./src/registry/root\";\n\nexport * from \"./src/registry\";\nexport { CRootNode } from \"./src/registry/root\";\nexport * from \"./src/core/Component\";\n\n/**\n * Launches the runtime with given top-level template on the specified platform.\n *\n * @param {IPlatform} platform - The platform on which to launch the template.\n * @param {string} template - The template to launch with.\n * @return {IArrmatron} The root context object.\n */\nexport const launch = (platform: IPlatform, template: string): IArrmatron => {\n const root = new CRootNode(template).createArrmatron(platform);\n\n root.up({}, true);\n\n return root;\n};\n"],
5
+ "mappings": "AAEA,OAAS,aAAAA,MAAiB,sBAE1B,WAAc,iBACd,OAAS,aAAAA,MAAiB,sBAC1B,WAAc,uBASP,IAAMC,EAAS,CAACC,EAAqBC,IAAiC,CAC3E,IAAMC,EAAO,IAAIJ,EAAUG,CAAQ,EAAE,gBAAgBD,CAAQ,EAE7D,OAAAE,EAAK,GAAG,CAAC,EAAG,EAAI,EAETA,CACT",
6
+ "names": ["CRootNode", "launch", "platform", "template", "root"]
7
+ }
@@ -0,0 +1,19 @@
1
+ # Glossary
2
+
3
+ | _Term_ | _Description_ |
4
+ | ----------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
5
+ | `Program` | A formal prescription given to a runtime to process (to apply trasformation rules in some order) incoming data. |
6
+ | `Type` | A specification that defines the possible values that can be reffered by a variable. |
7
+ | `Variable` | A program entity, which may reffer some data value. |
8
+ | `Object-oriented programming` | A programming style that evolves around composing components, which interact with each others by handling streams of events. |
9
+ | `Component` | An individual runtime entity that has a lifecycle, state, and behavior. Components can interact with others and are treated as black boxes. |
10
+ | `Class` | A design-time specification for the state and behavior of a component. It provides guidance for the runtime to create and manage instances of the component. |
11
+ | `State` | A private data structure that is managed by a component. |
12
+ | `Property` | A public getter/setter pair that allows access to a state value by a specified key. |
13
+ | `Behavior` | A specification that defines how a component should change its state in response to external impacts. |
14
+ | `Interface` | A design-time specification of the methods and signatures that can be used to interact with a component. |
15
+ | `Composition` | The | parent-child and context-content relationships between components. It defines the scope and lifecycle of the components that they can interact with. |
16
+ | `Template` | A text written in a formal language that allows for the description of component composition and property binding in a declarative way, focused on the desired outcome rather than the implementation details. |
17
+ | `Property binding` | A formal sentence that expresses a dependency between the value of a target component's property and other properties. It ensures that the target property is updated whenever the dependency changes. |
18
+ | `Property propagation` | A one-way binding that passes property values from a container component to its contents. |
19
+ | `Hook` | A component-bound method that is called by the runtime at specific points in the component's lifecycle. |
package/docs/hello.md ADDED
@@ -0,0 +1,46 @@
1
+ # Hello, world
2
+
3
+ The code you have provided is a combination of XML and JavaScript that utilizes the arrmatura framework to create a web application.
4
+
5
+ ## templates.xml
6
+
7
+ The templates.xml file defines two components: "Application" and "Main". The "Application" component is the root component of the application and contains a single instance of the "Main" component. The "Main" component is defined as a div element that displays a greeting, which consists of a static string ("Hello") and a dynamic value (name).
8
+
9
+ ```xml
10
+ <component id="Application">
11
+ <Main name="world"/>
12
+ </component>
13
+
14
+ <component id="Main">
15
+ <div title="{#greeting}, {@name | upper}!"></div>
16
+ </component>
17
+ ```
18
+
19
+ ## index.ts
20
+
21
+ In the index.ts file, the arrmatura framework is imported and used to render the application.
22
+
23
+ ```javascript
24
+ import { arrmatura } from 'arrmatura';
25
+ import templates from './templates.xml';
26
+
27
+ arrmatura({
28
+ template: '<Application />'
29
+ types: [templates],
30
+ resources: {
31
+ greeting: 'Hello',
32
+ },
33
+ functions: {
34
+ upper: (x) => x.toUpperCase(),
35
+ },
36
+ });
37
+ ```
38
+
39
+ The arrmatura function is passed several arguments:
40
+
41
+ - template: Specifies the root component of the application, which is <Application />.
42
+ - types: An array of component templates, in this case, the contents of the templates.xml file.
43
+ - resources: An object that contains the static data used in the application. In this case, a single resource greeting with the value "Hello" is provided.
44
+ - functions: An object that contains functions that can be used in component templates. In this case, a single function upper is provided, which takes a string as an argument and returns the uppercase version of the string.
45
+
46
+ When the arrmatura function is executed, it creates an instance of the "Application" component and renders it to the page. The "Main" component is then rendered as a child of the "Application" component, and its title is set to the result of evaluating the expression "{#greeting}, {@name | upper}!". This expression uses a combination of static data (greeting), dynamic data (name), and a function (upper) to create the greeting that is displayed in the div element.
package/docs/manual.md ADDED
@@ -0,0 +1,312 @@
1
+ #Templates
2
+
3
+ **Template** is a xml-based notation defining a components composition, events and data flow.
4
+
5
+ ## Insight
6
+
7
+ ```html
8
+
9
+ <component id="NavTreeItem">
10
+ <a href="id">
11
+ <span>{name | slice:0:50 | capitalize}</span>
12
+ <span If="label" class="label label-{type}">{label}</span>
13
+ </a>
14
+ </component>
15
+
16
+ <component id="NavTree">
17
+ <ul class="nav">
18
+ <li class="nav-item {item.class}" Each="item of data">
19
+ <NavTreeItem (...)="{item}">
20
+ <NavTree If="item.subs" data="{item.subs}" />
21
+ </li>
22
+ </ul>
23
+ </component>
24
+ ```
25
+
26
+ ## Composition Control flow.
27
+
28
+ ### Conditionals.
29
+
30
+ With `if` attribute, an element(and its inner context) presents only if value of expression is truthy.
31
+
32
+ ```html
33
+ <div ... If="enabled">...</div>
34
+ ```
35
+
36
+ #### full `then-else` syntax
37
+
38
+ ```html
39
+ <Fragment If="enabled">
40
+ <Then><Case1 /></Then>
41
+ <Else><Case2 /></Else>
42
+ </Fragment>
43
+ ```
44
+
45
+ ### Iterations.
46
+
47
+ `each` attribute multiplies component instances along items from given array.
48
+
49
+ ```html
50
+ <ul>
51
+ <li Each="item of data">
52
+ <a href="/item/{item.id}">{item.position}. {item.name}</span>
53
+ </li>
54
+ </ul>
55
+ ```
56
+
57
+ > - items MUST HAVE unique `id` field
58
+
59
+ ### Fragment.
60
+
61
+ `<Fragment>` is a transparent container and works just like a parens for multiple components.
62
+
63
+ ```html
64
+ <Fragment If="enabled"> <innerContent1 />...<innerContentN /> </Fragment>
65
+ ```
66
+
67
+ ## Dynamic tags.
68
+
69
+ Used to calculate tag dunamically at runtime.
70
+
71
+ ```html
72
+ <Dynamic As="Field.{type}" ...></Dynamic>
73
+ ```
74
+
75
+ > it will fallback to a `Field` if a specific type not found.
76
+
77
+ ## Properties.
78
+
79
+ Component state can be mutated different ways listed below.
80
+ State updates lead to redraw UI and notify subscribers(left arrows)
81
+ Updating data is compared with existing state values for 'sameness' (same set of same values).
82
+
83
+ ### with scalar literals
84
+
85
+ `prop1="'somestring'"` puts a literal into `prop1` property.
86
+
87
+ > - 'true', 'false' values are narrowed to boolean,
88
+ > - numbers has been narrowed to number type.
89
+
90
+ ### with resources values
91
+
92
+ `R`-prefix used to refer any value in the resource bundle.
93
+
94
+ `prop="R.resId"` assigns `resId` resource value to `prop`.
95
+
96
+ ### with result of expression
97
+
98
+ `prop="{prop2}"` assigns value of `prop2` property of the current scope.
99
+
100
+ `prop="{data.key}"` assigns value of `data.key`.
101
+
102
+ `prop="{!prop2}"` assigns inverted value of `prop2`
103
+
104
+ `(...)="{data}"` special `(...)` notation used to spread keys/values of `data` into properties of a target entity.
105
+
106
+ ### with result of chain of pipes
107
+
108
+ `prop="{some | pipeFn1 : 'strLiteral1' : 1 : true | pipeFn2 : property2 | pipeFn2 : R.resourceId}` applies chain of pipes.
109
+
110
+ > - Pipe functions can be chained. Result of the previous one passed as a first argument to the next one.
111
+ > - Optional colon-separated arguments can be passed to a pipe function as second, third arguments.
112
+ > - Use shortcuts like `==, && , ??, ?, >, <, []` for `equals, and, or, then, less, greater, dot` functions respectively.
113
+ > - There is no operation priority, they applied in left-to-right order.
114
+
115
+ ### `data-*` attributes
116
+
117
+ All `data-[key]` attributes will be collected into single `data` object property under its keys.
118
+
119
+ ### References.
120
+
121
+ Add `Ref` attribute to any component to get refer it in `arrows` expressions.
122
+
123
+ ```html
124
+ <UserService Ref="user" /> <UserAvatar data="<- user.profile" onSave="-> user.update" />
125
+ ```
126
+
127
+ ## Left arrow expression
128
+
129
+ `data="<- ref.prop"` makes a hot subscription to any property of orbitrary component in the current or upper scopes.
130
+
131
+ > use pipes to adapt received value `data="<- ref.prop | adjustFn"`.
132
+
133
+ ## Right arrow expression
134
+
135
+ Right arrow creates a function, that
136
+
137
+ - `action="data-> ref.submit(data)"` invokes `scope.refs[ref].submit(data)` action with an `data` object as parameter.
138
+
139
+ - `action="-> ref.submit(prop1)"` invokes `scope.refs[ref].submit(data)` action with a value of property `prop1` as parameter.
140
+
141
+ - `action="-> ref.prop1"` updates container state for given key `scope.refs[ref].up({ prop1: data })`.
142
+
143
+ > `action="data-> ref.action(data | prepare)` pipes will be applied on `data`-object before it passed to the action.
144
+
145
+ > `click="-> opened"` if `ref` is omitted, then a target will be a scope component `scope.up({opened:data})`
146
+
147
+ > `click="-> *"` will spread data to state of a scope component `scope.up(data)`
148
+
149
+ #### Right arrows with inline payload
150
+
151
+ Often, it is shorter to pass payload inline instead of using `data` property.
152
+
153
+ - `click="data-> * = data | assignKeyValue:'key':value"` updates a scope properties with `data` object.
154
+ - `click="-> prop" data="data"` updates a given scope property of owner with `data` object.
155
+ - `click="-> prop='literalValue'"` updates a given scope property of owner with literal.
156
+
157
+ ## Connector
158
+
159
+ Special build-in `Connector` component serves for async data binding
160
+ It acts with timeout(0 by default) and debounces if any:
161
+
162
+ ```html
163
+ <!-- `data` works as a `trigger`, if none specified. -->
164
+ <Connector data="<- todo.shownItems|adjust" change="-> someData" />
165
+
166
+ <!-- `change` is invokes with `data` on `trigger` changed. -->
167
+ <Connector
168
+ data="someData"
169
+ trigger="<- todo.shownItemsCount"
170
+ timeout="100"
171
+ change="data-> discriminant=data|calculate"
172
+ />
173
+ ```
174
+
175
+ ## Slots
176
+
177
+ Slots are placeholders to inject an inner content of component usage tag.
178
+
179
+ ```html
180
+ <Comp>
181
+ <!-- inner content of component usage -->
182
+ <InnerContent />
183
+ </Comp>
184
+ ```
185
+
186
+ ```html
187
+ <component id="Comp">
188
+ <div class="container">
189
+ <!-- Inner content will replace <Slot/> -->
190
+ <Slot>
191
+ </div>
192
+ </component>
193
+ ```
194
+
195
+ ### Multi-part extra content.
196
+
197
+ Inner content could be multiple-part and thus, distributed separately inside component template.
198
+
199
+ ```html
200
+ <Comp>
201
+ <Comp:key1><Extra1 /></Comp:key1>
202
+ <Comp:key2><Extra2 /></Comp:key2>
203
+ <DefaultSlotContent />
204
+ </Comp>
205
+ ```
206
+
207
+ ```html
208
+ <div class="component template">
209
+
210
+ <!-- <Extra1/> will be placed here-->
211
+ <Slot Key="key1">
212
+
213
+ <!-- special `slot(key)` conditional expression may be used to check if non-empty slot content passed. -->
214
+ <div class="comp" If="slot(key2)">
215
+ <!-- <Extra2/> will be placed here -->
216
+ <Slot Key="key2">
217
+ </div>
218
+
219
+ <!-- <DefaultContent/> will be placed here -->
220
+ <Slot>
221
+ </div>
222
+ ```
223
+
224
+ # Custom components
225
+
226
+ There is a [Component] class that could be used an base ancestor for custom components.
227
+
228
+ While designing custom components you can
229
+
230
+ - to define life-cycle hooks;
231
+ - to add getters/setter for its properties;
232
+ - to define `__getProperty(propName)` to return value of any property by its name
233
+ - to define `__stateChanged(changes)` to intercept appluing state changes
234
+ - to define action handlers like `doSomethig(data: any): object`, which may return a delta object for updating a component state;
235
+ - to use context methods like `up(delta)`, `emit('ref-target', data)`, `defer(fn)`.
236
+
237
+ ```typescript
238
+ class MyService extends Component {
239
+
240
+ constructor(initials: Hash, ctx: ICtx) {
241
+ Object.asign(this, initials);
242
+ this.ctx = ctx;
243
+ }
244
+
245
+ // life-cycle hook called once on component is inited
246
+ init() {
247
+ this.cancel = api.listen(this)
248
+ // ...or using $.defer()
249
+ this.ctx.defer(api.listen2(this));
250
+
251
+ // will update component state with returned result
252
+ return {
253
+ prop1:'value',
254
+ // can be promise as well
255
+ prop2: Promise.resolve(2)
256
+ }
257
+ }
258
+
259
+ // life-cycle hook called once on component is done
260
+ done (){
261
+ this.cancel();
262
+ }
263
+
264
+ // to intercept getting of any property
265
+ __getProperty(key: string) {
266
+ this.log('getProperty', key)
267
+ return this[key]
268
+
269
+ // to intercept state changes
270
+ __stateChanged(changes: Map) {
271
+ }
272
+
273
+ // property getter
274
+ getSrc(){
275
+ return this.url.toString()
276
+ }
277
+
278
+ // property setter
279
+ setSrc(value){
280
+ this.url = URL.parse(value)
281
+ }
282
+
283
+ // getter can return promise
284
+ async getData() {
285
+ return this.fetchData()
286
+ }
287
+
288
+ // action handler. To be invoked with '-> ref.someAction' notation
289
+ onSomeAction(data: any) {
290
+ if (asyncMode) {
291
+ return promise.then(() => delta)
292
+ }
293
+ // delta object to update component state
294
+ return {
295
+ // instant value for 'prop'
296
+ prop: data.value,
297
+ // async evaluation for 'prop'. 'Promise' postfix is optional.
298
+ propPromise: T.fetchProp(),
299
+ // async spread
300
+ '...': Promise.resolve({
301
+ prop1: 'val1'
302
+ prop2: 'val2'
303
+ })
304
+ }
305
+ }
306
+
307
+ toast (message) {
308
+ // emit action event
309
+ this.emit('toasters.onSend(data)', { message });
310
+ };
311
+ }
312
+ ```
package/index.ts CHANGED
@@ -1,18 +1,20 @@
1
- import { ICtx, IPlatform } from "arrmatura-api/types";
2
- import { CRootNode } from "./src/core/root";
1
+ import { IArrmatron, IPlatform } from "arrmatura/types";
3
2
 
4
- export { Registry } from "./src/core";
5
- export { CRootNode } from "./src/core/root";
3
+ import { CRootNode } from "./src/registry/root";
4
+
5
+ export * from "./src/registry";
6
+ export { CRootNode } from "./src/registry/root";
7
+ export * from "./src/core/Component";
6
8
 
7
9
  /**
8
10
  * Launches the runtime with given top-level template on the specified platform.
9
11
  *
10
12
  * @param {IPlatform} platform - The platform on which to launch the template.
11
13
  * @param {string} template - The template to launch with.
12
- * @return {ICtx} The root context object.
14
+ * @return {IArrmatron} The root context object.
13
15
  */
14
- export const launch = (platform: IPlatform, template: string): ICtx => {
15
- const root = new CRootNode(template).createContext(platform);
16
+ export const launch = (platform: IPlatform, template: string): IArrmatron => {
17
+ const root = new CRootNode(template).createArrmatron(platform);
16
18
 
17
19
  root.up({}, true);
18
20
 
package/package.json CHANGED
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "name": "arrmatura",
3
- "version": "6.2.1",
3
+ "version": "6.3.2",
4
4
  "description": "Arrmatura runtime engine",
5
5
  "author": "alitskevich@gmail.com",
6
6
  "license": "ISC",
7
7
  "type": "module",
8
- "main": "index.ts",
8
+ "exports": {
9
+ "import": "./index.ts",
10
+ "require": "./dist/index.js"
11
+ },
9
12
  "files": [
10
- "src/**/*"
13
+ "src",
14
+ "dist",
15
+ "index.ts",
16
+ "types.ts",
17
+ "docs/**/*"
11
18
  ],
12
19
  "dependencies": {
13
- "arrmatura-api": "1.0.2",
14
- "ultimus": "2.1.4"
20
+ "arrmatura": "6.3.2",
21
+ "ultimus": "2.1.10"
15
22
  },
16
23
  "scripts": {
24
+ "esbuild": "esbuild index.ts --bundle --outdir=./dist --platform=browser --format=esm --sourcemap --target=esnext --external:* --minify",
17
25
  "pnpm:publish": "pnpm publish --no-git-checks"
18
26
  }
19
27
  }