jaxs 0.3.1 → 0.4.0
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/dist/jaxs.d.ts +634 -0
- package/dist/jaxs.js +793 -1054
- package/dist/jaxs.umd.cjs +1 -0
- package/package.json +41 -30
- package/.env +0 -1
- package/README.md +0 -15
- package/bun.lockb +0 -0
- package/bundle.ts +0 -5
- package/bunfig.toml +0 -0
- package/cypress/e2e/add-remove-nested-children.cy.js +0 -39
- package/cypress/e2e/add-remove-root-children.cy.js +0 -37
- package/cypress/e2e/svg-renders.cy.js +0 -10
- package/cypress/jaxs-apps/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/add-remove-nested-children.jsx +0 -85
- package/cypress/jaxs-apps/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/add-remove-root-children.jsx +0 -54
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js +0 -1022
- package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-nested-children.html +0 -12
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +0 -1665
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js +0 -1011
- package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js.map +0 -1
- package/cypress/jaxs-apps/dist/add-remove-root-children.html +0 -15
- package/cypress/jaxs-apps/dist/svg.04290504.js +0 -644
- package/cypress/jaxs-apps/dist/svg.04290504.js.map +0 -1
- package/cypress/jaxs-apps/dist/svg.html +0 -11
- package/cypress/jaxs-apps/svg.html +0 -11
- package/cypress/jaxs-apps/svg.jsx +0 -15
- package/cypress/support/commands.js +0 -25
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -10
- package/src/app.ts +0 -64
- package/src/debugging.js +0 -5
- package/src/jaxs.ts +0 -7
- package/src/jsx.js +0 -27
- package/src/messageBus.ts +0 -70
- package/src/navigation/findHref.js +0 -10
- package/src/navigation/routeState.js +0 -15
- package/src/navigation/setupHistory.js +0 -38
- package/src/navigation/setupNavigation.js +0 -25
- package/src/navigation.ts +0 -2
- package/src/rendering/change/compile.ts +0 -1
- package/src/rendering/change/instructions/attributes.ts +0 -81
- package/src/rendering/change/instructions/children.ts +0 -127
- package/src/rendering/change/instructions/element.ts +0 -49
- package/src/rendering/change/instructions/events.ts +0 -51
- package/src/rendering/change/instructions/generate.ts +0 -122
- package/src/rendering/change/instructions/idMap.js +0 -55
- package/src/rendering/change/instructions/node.ts +0 -55
- package/src/rendering/change/instructions/text.ts +0 -10
- package/src/rendering/change.ts +0 -139
- package/src/rendering/dom/attributesAndEvents.ts +0 -33
- package/src/rendering/dom/create.ts +0 -68
- package/src/rendering/dom/svg.ts +0 -18
- package/src/rendering/templates/bound.js +0 -56
- package/src/rendering/templates/children.ts +0 -99
- package/src/rendering/templates/root.ts +0 -55
- package/src/rendering/templates/tag.ts +0 -92
- package/src/rendering/templates/text.ts +0 -17
- package/src/state/equality.js +0 -36
- package/src/state/stores.js +0 -63
- package/src/state/testingTypes.js +0 -6
- package/src/state.js +0 -89
- package/src/types.ts +0 -152
- package/src/views/conditionals.jsx +0 -18
- package/src/views/link.jsx +0 -5
- package/src/views.js +0 -7
- package/tsconfig.json +0 -26
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Dom,
|
|
3
|
-
DomCollection,
|
|
4
|
-
RenderKit,
|
|
5
|
-
Template,
|
|
6
|
-
TextValue,
|
|
7
|
-
} from '../../types';
|
|
8
|
-
import { TextTemplate } from './text';
|
|
9
|
-
|
|
10
|
-
export const ensureArray = (children: Template | Template[]): Template[] => {
|
|
11
|
-
if (Array.isArray(children)) {
|
|
12
|
-
return children.flat();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!children) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return [children];
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/* three options for children
|
|
23
|
-
1. there is no view
|
|
24
|
-
2. view is an array, recurse
|
|
25
|
-
3. view is a renderable thing
|
|
26
|
-
*/
|
|
27
|
-
const recursiveRender = (
|
|
28
|
-
children: Template[],
|
|
29
|
-
renderKit: RenderKit,
|
|
30
|
-
rendered = [] as DomCollection,
|
|
31
|
-
): DomCollection => children.reduce(renderReducer(renderKit), rendered).flat();
|
|
32
|
-
|
|
33
|
-
const renderReducer =
|
|
34
|
-
(renderKit: RenderKit) =>
|
|
35
|
-
(aggregate: DomCollection, view: Template): DomCollection => {
|
|
36
|
-
if (!view) return aggregate;
|
|
37
|
-
|
|
38
|
-
if (Array.isArray(view)) {
|
|
39
|
-
const dom = recursiveRender(view, renderKit, aggregate) as DomCollection;
|
|
40
|
-
return dom;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
view.render(renderKit).forEach((template) => aggregate.push(template));
|
|
44
|
-
|
|
45
|
-
return aggregate;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const replaceTextNodes = (child: TextValue | Template) => {
|
|
49
|
-
if (isTextNode(child)) {
|
|
50
|
-
return textNode(child as TextValue);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return child;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const isTextNode = (child: TextValue | Template) => {
|
|
57
|
-
return typeof child === 'string' || typeof child === 'number';
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const textNode = (content: TextValue) => {
|
|
61
|
-
return new TextTemplate(content);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const withSvgFlag = (isSvg: boolean) => (template: Template) => {
|
|
65
|
-
template && (template.isSvg = template.isSvg || isSvg)
|
|
66
|
-
return template
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class Children implements Template {
|
|
70
|
-
collection: Template[];
|
|
71
|
-
parentElement: Element | undefined;
|
|
72
|
-
isSvg: boolean;
|
|
73
|
-
|
|
74
|
-
constructor(jsxChildren: Template[], isSvg = false) {
|
|
75
|
-
this.collection = ensureArray(jsxChildren)
|
|
76
|
-
this.collection = this.collection.map(replaceTextNodes) as Template[];
|
|
77
|
-
this.collection = this.collection.flat() as Template[];
|
|
78
|
-
this.collection = this.collection.map(withSvgFlag(isSvg))
|
|
79
|
-
this.isSvg = isSvg;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
render(renderKit: RenderKit, parentElement: Element | undefined) {
|
|
83
|
-
this.parentElement = parentElement;
|
|
84
|
-
const dom = this.generateDom(renderKit);
|
|
85
|
-
this.attachToParent(dom);
|
|
86
|
-
return dom;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
generateDom(renderKit: RenderKit) {
|
|
90
|
-
return recursiveRender(this.collection, renderKit);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
attachToParent(dom: DomCollection) {
|
|
94
|
-
if (this.parentElement === undefined) return;
|
|
95
|
-
|
|
96
|
-
const parent = this.parentElement as Element;
|
|
97
|
-
dom.forEach((node: Dom) => parent.appendChild(node));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DomCollection,
|
|
3
|
-
RenderKit,
|
|
4
|
-
Template,
|
|
5
|
-
} from '../../types';
|
|
6
|
-
|
|
7
|
-
export class Root {
|
|
8
|
-
template: Template;
|
|
9
|
-
selector: string;
|
|
10
|
-
renderKit: RenderKit;
|
|
11
|
-
dom: DomCollection;
|
|
12
|
-
parentElement: Element | null;
|
|
13
|
-
|
|
14
|
-
constructor(template: Template, selector: string, renderKit: RenderKit) {
|
|
15
|
-
this.template = template;
|
|
16
|
-
this.selector = selector;
|
|
17
|
-
this.renderKit = renderKit;
|
|
18
|
-
this.dom = [];
|
|
19
|
-
this.parentElement = null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
renderAndAttach(renderKit: RenderKit) {
|
|
23
|
-
this.parentElement = this.getParentElement();
|
|
24
|
-
this.dom = this.render({...renderKit, parent: this.parentElement});
|
|
25
|
-
|
|
26
|
-
if (this.parentElement) {
|
|
27
|
-
this.attach();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
render(renderKit: RenderKit) {
|
|
32
|
-
return this.template.render(renderKit);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
attach() {
|
|
36
|
-
this.parentElement && (this.parentElement.innerHTML = '');
|
|
37
|
-
this.dom.forEach((element) => {
|
|
38
|
-
this.parentElement && this.parentElement.appendChild(element);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getParentElement() {
|
|
43
|
-
return this.renderKit.document.querySelector(this.selector);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const render = (
|
|
48
|
-
template: Template,
|
|
49
|
-
selector: string,
|
|
50
|
-
renderKit: RenderKit,
|
|
51
|
-
) => {
|
|
52
|
-
const root = new Root(template, selector, renderKit);
|
|
53
|
-
root.renderAndAttach(renderKit);
|
|
54
|
-
return root;
|
|
55
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Attributes,
|
|
3
|
-
DomCollection,
|
|
4
|
-
EventAttributes,
|
|
5
|
-
RenderKit,
|
|
6
|
-
Template,
|
|
7
|
-
} from '../../types';
|
|
8
|
-
|
|
9
|
-
import { createDecoratedNode } from '../dom/create';
|
|
10
|
-
import { separateAttrsAndEvents } from '../dom/attributesAndEvents';
|
|
11
|
-
import { isSvgTag, createSvgNode } from '../dom/svg'
|
|
12
|
-
import { Children } from './children';
|
|
13
|
-
|
|
14
|
-
export class Tag implements Template {
|
|
15
|
-
type: string;
|
|
16
|
-
events: EventAttributes;
|
|
17
|
-
attributes: Attributes;
|
|
18
|
-
children: Children;
|
|
19
|
-
isSvg: boolean;
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
tagType: string,
|
|
23
|
-
combinedAttributes: Attributes,
|
|
24
|
-
children: Template[],
|
|
25
|
-
isSvg = false
|
|
26
|
-
) {
|
|
27
|
-
this.type = tagType;
|
|
28
|
-
|
|
29
|
-
const { events, attributes } = separateAttrsAndEvents(combinedAttributes);
|
|
30
|
-
this.events = events;
|
|
31
|
-
this.attributes = attributes;
|
|
32
|
-
|
|
33
|
-
this.isSvg = isSvg || isSvgTag(this.type);
|
|
34
|
-
this.children = new Children(children, this.isSvg);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
render(renderKit: RenderKit): DomCollection {
|
|
38
|
-
const dom = this.generateDom(renderKit);
|
|
39
|
-
if (!dom) return [];
|
|
40
|
-
|
|
41
|
-
this.children.render(renderKit, dom);
|
|
42
|
-
return [dom];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
generateDom(renderKit: RenderKit) {
|
|
46
|
-
if (this.isSvg) {
|
|
47
|
-
return this.generateSvnDom(renderKit)
|
|
48
|
-
} else {
|
|
49
|
-
return this.generateHtmlDom(renderKit)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
generateHtmlDom(renderKit: RenderKit) {
|
|
54
|
-
const node = createDecoratedNode(
|
|
55
|
-
this.type,
|
|
56
|
-
this.attributes,
|
|
57
|
-
this.events,
|
|
58
|
-
renderKit,
|
|
59
|
-
);
|
|
60
|
-
node.__jsx = this.key();
|
|
61
|
-
return node;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
generateSvnDom(renderKit: RenderKit) {
|
|
65
|
-
const node = createSvgNode(
|
|
66
|
-
this.type,
|
|
67
|
-
this.attributes,
|
|
68
|
-
renderKit,
|
|
69
|
-
);
|
|
70
|
-
node.__jsx = this.key();
|
|
71
|
-
return node;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
key() {
|
|
75
|
-
return this.attributes.key || this.source() || this.createKey();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
source() {
|
|
79
|
-
if (this.attributes.__source) {
|
|
80
|
-
const { fileName, lineNumber, columnNumber } = this.attributes.__source;
|
|
81
|
-
return `${fileName}:${lineNumber}:${columnNumber}`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
createKey() {
|
|
86
|
-
const id = this.attributes.id ? `#${this.attributes.id}` : '';
|
|
87
|
-
const type = this.attributes.type ? `[type=${this.attributes.type}]` : '';
|
|
88
|
-
const name = this.attributes.name ? `[name=${this.attributes.name}]` : '';
|
|
89
|
-
|
|
90
|
-
return `${this.type}${id}${type}${name}`;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { JsxId, RenderKit, Template, TextValue } from '../../types';
|
|
2
|
-
import { createTextNode } from '../dom/create';
|
|
3
|
-
|
|
4
|
-
export class TextTemplate implements Template {
|
|
5
|
-
value: string;
|
|
6
|
-
|
|
7
|
-
constructor(content: TextValue) {
|
|
8
|
-
this.value = content.toString();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
render(renderKit: RenderKit) {
|
|
12
|
-
const textNode = createTextNode(this.value, renderKit.document);
|
|
13
|
-
if (!textNode) return [];
|
|
14
|
-
(textNode as unknown as JsxId).__jsx = 'TextNode';
|
|
15
|
-
return [textNode];
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/state/equality.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { isObject, isArray } from './testingTypes'
|
|
2
|
-
|
|
3
|
-
export const areElementEqual = (oldValue, newValue) => oldValue === newValue
|
|
4
|
-
|
|
5
|
-
const keyLengthSame = (oldValue, newValue) =>
|
|
6
|
-
Object.keys(oldValue).length === Object.keys(newValue).length
|
|
7
|
-
|
|
8
|
-
export const areObjectsEqual = (oldValue, newValue) => {
|
|
9
|
-
if (!(isObject(oldValue) && isObject(newValue))) return false
|
|
10
|
-
if (!keyLengthSame(oldValue, newValue)) return false
|
|
11
|
-
|
|
12
|
-
Object.keys(oldValue).every((key) => {
|
|
13
|
-
const oldInnerValue = oldValue[key]
|
|
14
|
-
const newInnerValue = newValue[key]
|
|
15
|
-
|
|
16
|
-
return areEqual(oldInnerValue, newInnerValue)
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const areArraysEqual = (oldValue, newValue) => {
|
|
21
|
-
if (!(isArray(oldValue) && isArray(newValue))) return false
|
|
22
|
-
if (oldValue.length !== newValue.length) return false
|
|
23
|
-
|
|
24
|
-
oldValue.every((oldInnerValue, index) => {
|
|
25
|
-
const newInnerValue = newValue[index]
|
|
26
|
-
|
|
27
|
-
return areEqual(oldInnerValue, newInnerValue)
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const areEqual = (oldValue, newValue) => {
|
|
32
|
-
if (isObject(oldValue)) return areObjectsEqual(oldValue, newValue)
|
|
33
|
-
if (isArray(oldValue)) return areArraysEqual(oldValue, newValue)
|
|
34
|
-
|
|
35
|
-
return areElementEqual(oldValue, newValue)
|
|
36
|
-
}
|
package/src/state/stores.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { areElementEqual, areArraysEqual, areObjectsEqual } from './equality'
|
|
2
|
-
|
|
3
|
-
export class GeneralStore {
|
|
4
|
-
nullEvent = {}
|
|
5
|
-
|
|
6
|
-
constructor ({ name, value, parent }) {
|
|
7
|
-
this.name = name
|
|
8
|
-
this.value = value
|
|
9
|
-
this.parent = parent
|
|
10
|
-
this.initialState = value
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
update (newValue) {
|
|
14
|
-
if (this.isEqual(newValue)) return
|
|
15
|
-
|
|
16
|
-
this.value = newValue
|
|
17
|
-
return this.parent.publish(this.event())
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
reset () {
|
|
21
|
-
this.update(this.initialState)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
isEqual (newValue) {
|
|
25
|
-
return areElementEqual(this.value, newValue)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
event () {
|
|
29
|
-
return {
|
|
30
|
-
name: this.name,
|
|
31
|
-
value: this.value
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class BooleanStore extends GeneralStore {
|
|
37
|
-
toggle () {
|
|
38
|
-
this.update(!this.value)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class NumericStore extends GeneralStore {
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class StringStore extends GeneralStore {
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class ListStore extends GeneralStore {
|
|
49
|
-
isEqual (newValue) {
|
|
50
|
-
return areArraysEqual(this.value, newValue)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
push (newValue) {
|
|
54
|
-
const value = [...this.value, newValue]
|
|
55
|
-
this.update(value)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class RecordStore extends GeneralStore {
|
|
60
|
-
isEqual (newValue) {
|
|
61
|
-
return areObjectsEqual(this.value, newValue)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const isBoolean = (value) => typeof (value) === 'boolean'
|
|
2
|
-
export const isNumber = (value) => typeof (value) === 'number'
|
|
3
|
-
export const isString = (value) => typeof (value) === 'string'
|
|
4
|
-
export const isArray = (value) => Array.isArray(value)
|
|
5
|
-
export const isObject = (value) =>
|
|
6
|
-
value !== null && !isArray(value) && typeof (value) === 'object'
|
package/src/state.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isArray,
|
|
3
|
-
isObject,
|
|
4
|
-
isBoolean,
|
|
5
|
-
isNumber,
|
|
6
|
-
isString
|
|
7
|
-
} from './state/testingTypes'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
GeneralStore,
|
|
11
|
-
ListStore,
|
|
12
|
-
NumericStore,
|
|
13
|
-
BooleanStore,
|
|
14
|
-
StringStore,
|
|
15
|
-
RecordStore
|
|
16
|
-
} from './state/stores'
|
|
17
|
-
|
|
18
|
-
const eventPrefix = 'state-change'
|
|
19
|
-
export const eventName = (name) => `${eventPrefix}:${name}`
|
|
20
|
-
|
|
21
|
-
export class State {
|
|
22
|
-
constructor (publish) {
|
|
23
|
-
this.publisher = publish
|
|
24
|
-
this.stores = {}
|
|
25
|
-
this.events = []
|
|
26
|
-
this.transacting = false
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
create (name, value) {
|
|
30
|
-
const StoreClass = this.storeTypeFor(value)
|
|
31
|
-
const store = new StoreClass({ name, value, parent: this })
|
|
32
|
-
this.addStore(name, store)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
add (store) {
|
|
36
|
-
const name = store.name
|
|
37
|
-
this.addStore(name, store)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getStore (name) {
|
|
41
|
-
return this.stores[name]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addStore (name, store) {
|
|
45
|
-
this.stores[name] = store
|
|
46
|
-
this[name] = store
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
storeTypeFor (value) {
|
|
50
|
-
if (isArray(value)) return ListStore
|
|
51
|
-
if (isObject(value)) return RecordStore
|
|
52
|
-
if (isNumber(value)) return NumericStore
|
|
53
|
-
if (isBoolean(value)) return BooleanStore
|
|
54
|
-
if (isString(value)) return StringStore
|
|
55
|
-
|
|
56
|
-
return GeneralStore
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
publish (event) {
|
|
60
|
-
this.events.push(event)
|
|
61
|
-
if (!this.transacting) this.publishAll()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
publishAll () {
|
|
65
|
-
const publishedStores = []
|
|
66
|
-
this.events.reverse().forEach((event) => {
|
|
67
|
-
const { name, value } = event
|
|
68
|
-
if (!publishedStores.includes(name)) {
|
|
69
|
-
publishedStores.push(name)
|
|
70
|
-
this.publisher(`${eventPrefix}:${name}`, value)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
this.events = []
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
transaction (setter) {
|
|
77
|
-
this.transacting = true
|
|
78
|
-
setter(this)
|
|
79
|
-
this.transacting = false
|
|
80
|
-
this.publishAll()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
value () {
|
|
84
|
-
return Object.keys(this.stores).reduce((valueObject, key) => {
|
|
85
|
-
valueObject[key] = this.stores[key].value
|
|
86
|
-
return valueObject
|
|
87
|
-
}, {})
|
|
88
|
-
}
|
|
89
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// Rendering & Dom ------
|
|
2
|
-
import { State } from './state'
|
|
3
|
-
export type DomEventPublisher = (eventName: string, domEvent: Event) => void;
|
|
4
|
-
|
|
5
|
-
export type RenderKit = {
|
|
6
|
-
document: Document;
|
|
7
|
-
publish: DomEventPublisher;
|
|
8
|
-
subscribe: BusSubscribe;
|
|
9
|
-
state: State;
|
|
10
|
-
parent?: Element | null;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export interface JsxId {
|
|
14
|
-
__jsx: string;
|
|
15
|
-
}
|
|
16
|
-
export interface ExpandedElement extends Element, JsxId {
|
|
17
|
-
eventMaps: EventMaps;
|
|
18
|
-
}
|
|
19
|
-
export interface InputElement extends ExpandedElement {
|
|
20
|
-
// deno-lint-ignore no-explicit-any
|
|
21
|
-
value: any;
|
|
22
|
-
}
|
|
23
|
-
export type Dom = Text | ExpandedElement | SVGElement;
|
|
24
|
-
export type DomCollection = Dom[];
|
|
25
|
-
export type HtmlChildren =
|
|
26
|
-
| HTMLCollection
|
|
27
|
-
| NodeListOf<ChildNode>
|
|
28
|
-
| DomCollection;
|
|
29
|
-
export type TextValue = string | number;
|
|
30
|
-
export type EventMap = {
|
|
31
|
-
domEvent: string;
|
|
32
|
-
busEvent: string;
|
|
33
|
-
listener: EventListener;
|
|
34
|
-
};
|
|
35
|
-
export type EventMaps = Record<string, EventMap>;
|
|
36
|
-
|
|
37
|
-
// deno-lint-ignore no-explicit-any
|
|
38
|
-
export type Attributes = Record<string, any>;
|
|
39
|
-
export type EventAttributes = Record<string, string>;
|
|
40
|
-
export type AttributesAndEvents = {
|
|
41
|
-
attributes: Attributes;
|
|
42
|
-
events: EventAttributes;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type TemplateEventListeners = Record<string, EventListener>;
|
|
46
|
-
|
|
47
|
-
export interface Template {
|
|
48
|
-
isSvg?: boolean,
|
|
49
|
-
render: (
|
|
50
|
-
renderKit: RenderKit,
|
|
51
|
-
parentElement?: Element,
|
|
52
|
-
) => DomCollection;
|
|
53
|
-
}
|
|
54
|
-
export type TemplateClass = (attributes: Attributes) => Template;
|
|
55
|
-
|
|
56
|
-
export type ViewModel = (state: Record<string,any>) => State;
|
|
57
|
-
|
|
58
|
-
// Message Bus ----
|
|
59
|
-
export type BusEventName = string;
|
|
60
|
-
// deno-lint-ignore no-explicit-any
|
|
61
|
-
export type BusOptions = Record<string, any>;
|
|
62
|
-
// deno-lint-ignore no-explicit-any
|
|
63
|
-
export type BusPayload = any;
|
|
64
|
-
export type BusPublish = (eventName: BusEventName, payload: BusPayload) => void;
|
|
65
|
-
export type BusSubscribe = (
|
|
66
|
-
eventName: BusEventName,
|
|
67
|
-
listener: BusListener,
|
|
68
|
-
) => void;
|
|
69
|
-
export interface BusListenerKit {
|
|
70
|
-
publish: BusPublish;
|
|
71
|
-
eventName: BusEventName;
|
|
72
|
-
// deno-lint-ignore no-explicit-any
|
|
73
|
-
[key: string]: any;
|
|
74
|
-
}
|
|
75
|
-
export type BusListener = (
|
|
76
|
-
payload: BusPayload,
|
|
77
|
-
listenerKit: BusListenerKit,
|
|
78
|
-
) => void;
|
|
79
|
-
export type BusListenersMap = Record<BusEventName, BusPayload>;
|
|
80
|
-
|
|
81
|
-
// Change instructions
|
|
82
|
-
export type RemoveInstructionData = {
|
|
83
|
-
name: string;
|
|
84
|
-
isSvg?: boolean;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export type AttributeInstructionData = {
|
|
88
|
-
name: string;
|
|
89
|
-
value: string;
|
|
90
|
-
isSvg?: boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type EventInstructionData = {
|
|
94
|
-
name: string;
|
|
95
|
-
value: EventListener;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type UpdateEventInstructionData = {
|
|
99
|
-
name: string;
|
|
100
|
-
sourceValue: EventListener;
|
|
101
|
-
targetValue: EventListener;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export type InsertNodeData = {
|
|
105
|
-
parent: ExpandedElement;
|
|
106
|
-
index: number;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
type NullData = Record<string, never>;
|
|
110
|
-
|
|
111
|
-
export type InstructionData =
|
|
112
|
-
| RemoveInstructionData
|
|
113
|
-
| AttributeInstructionData
|
|
114
|
-
| EventInstructionData
|
|
115
|
-
| UpdateEventInstructionData
|
|
116
|
-
| InsertNodeData
|
|
117
|
-
| NullData;
|
|
118
|
-
|
|
119
|
-
export type Instruction = {
|
|
120
|
-
source: Dom;
|
|
121
|
-
target: Dom;
|
|
122
|
-
type: ChangeInstructions;
|
|
123
|
-
data: InstructionData;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export type Instructions = Array<Instruction>;
|
|
127
|
-
|
|
128
|
-
export enum ChangeInstructions {
|
|
129
|
-
removeNode,
|
|
130
|
-
insertNode, // can be to move an existing element in the dom, or to add one
|
|
131
|
-
replaceNode,
|
|
132
|
-
removeAttribute,
|
|
133
|
-
addAttribute,
|
|
134
|
-
updateAttribute,
|
|
135
|
-
removeEvent,
|
|
136
|
-
addEvent,
|
|
137
|
-
updateEvent,
|
|
138
|
-
changeValue,
|
|
139
|
-
changeText,
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export type Updater = (instruction: Instruction) => void;
|
|
143
|
-
|
|
144
|
-
export type App = {
|
|
145
|
-
publish?: BusPublish;
|
|
146
|
-
subscribe?: BusSubscribe;
|
|
147
|
-
// deno-lint-ignore no-explicit-any
|
|
148
|
-
bus?: any;
|
|
149
|
-
state?: State
|
|
150
|
-
renderKit: RenderKit;
|
|
151
|
-
render: (template: Template, selector: string) => Template;
|
|
152
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import jsx from '../jsx'
|
|
2
|
-
|
|
3
|
-
export const If = ({ condition, children }) => {
|
|
4
|
-
if (!condition) return
|
|
5
|
-
return <>{children}</>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const Unless = ({ condition, children }) => {
|
|
9
|
-
if (condition) return
|
|
10
|
-
return <>{children}</>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const IfElse = ({ condition, children }) => {
|
|
14
|
-
const [first, ...rest] = children
|
|
15
|
-
|
|
16
|
-
if (condition) return <>{first}</>
|
|
17
|
-
return <>{rest}</>
|
|
18
|
-
}
|
package/src/views/link.jsx
DELETED
package/src/views.js
DELETED
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleDetection": "force",
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"verbatimModuleSyntax": true,
|
|
13
|
-
"noEmit": true,
|
|
14
|
-
|
|
15
|
-
/* Linting */
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"strict": true,
|
|
18
|
-
"noFallthroughCasesInSwitch": true,
|
|
19
|
-
"forceConsistentCasingInFileNames": true,
|
|
20
|
-
|
|
21
|
-
/* Jaxs JSX */
|
|
22
|
-
"jsx": "react",
|
|
23
|
-
"jsxFactory": "jsx",
|
|
24
|
-
"jsxFragmentFactory": "jsx.fragment"
|
|
25
|
-
}
|
|
26
|
-
}
|