rumious 1.0.13 → 2.0.1

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.
Files changed (87) hide show
  1. package/dist/app/app.d.ts +10 -8
  2. package/dist/app/index.d.ts +0 -1
  3. package/dist/component/component.d.ts +15 -24
  4. package/dist/component/element.d.ts +10 -15
  5. package/dist/global.d.ts +15 -0
  6. package/dist/index.d.ts +7 -27
  7. package/dist/index.js +1042 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/jsx/component.d.ts +3 -0
  10. package/dist/jsx/dynamic.d.ts +2 -0
  11. package/dist/jsx/element.d.ts +9 -0
  12. package/dist/jsx/index.d.ts +4 -4
  13. package/dist/jsx/template.d.ts +25 -0
  14. package/dist/{app/module.d.ts → module/index.d.ts} +1 -1
  15. package/dist/ref/index.d.ts +1 -2
  16. package/dist/ref/ref.d.ts +37 -0
  17. package/dist/render/context.d.ts +7 -9
  18. package/dist/render/index.d.ts +4 -3
  19. package/dist/render/list.d.ts +16 -0
  20. package/dist/render/render.d.ts +3 -2
  21. package/dist/render/view.d.ts +19 -0
  22. package/dist/state/index.d.ts +1 -2
  23. package/dist/state/list.d.ts +14 -0
  24. package/dist/state/reactor.d.ts +15 -16
  25. package/dist/state/state.d.ts +11 -8
  26. package/dist/types/component.d.ts +5 -0
  27. package/dist/types/index.d.ts +3 -0
  28. package/dist/types/jsx.d.ts +16 -8
  29. package/dist/types/state.d.ts +8 -0
  30. package/dist/types/template.d.ts +5 -0
  31. package/dist/utils/checker.d.ts +2 -0
  32. package/package.json +34 -53
  33. package/rollup.config.js +21 -0
  34. package/src/app/app.ts +45 -0
  35. package/src/app/index.ts +1 -0
  36. package/src/component/component.ts +69 -0
  37. package/src/component/element.ts +76 -0
  38. package/src/component/index.ts +2 -0
  39. package/src/global.ts +20 -0
  40. package/src/index.ts +13 -0
  41. package/src/jsx/component.ts +17 -0
  42. package/src/jsx/dynamic.ts +87 -0
  43. package/src/jsx/element.ts +77 -0
  44. package/src/jsx/index.ts +7 -0
  45. package/src/jsx/template.ts +377 -0
  46. package/src/module/index.ts +7 -0
  47. package/src/ref/index.ts +1 -0
  48. package/src/ref/ref.ts +178 -0
  49. package/src/render/context.ts +11 -0
  50. package/src/render/index.ts +4 -0
  51. package/src/render/list.ts +115 -0
  52. package/src/render/render.ts +31 -0
  53. package/src/render/view.ts +101 -0
  54. package/src/state/index.ts +2 -0
  55. package/src/state/list.ts +96 -0
  56. package/src/state/reactor.ts +65 -0
  57. package/src/state/state.ts +68 -0
  58. package/src/types/component.ts +6 -0
  59. package/src/types/index.ts +3 -0
  60. package/src/types/state.ts +16 -0
  61. package/src/types/template.ts +7 -0
  62. package/src/utils/checker.ts +5 -0
  63. package/tsconfig.json +20 -0
  64. package/README.md +0 -7
  65. package/dist/context/context.d.ts +0 -12
  66. package/dist/context/index.d.ts +0 -1
  67. package/dist/index.cjs +0 -1
  68. package/dist/index.esm.js +0 -1
  69. package/dist/index.global.d.ts +0 -46
  70. package/dist/index.min.js +0 -1
  71. package/dist/performance/index.d.ts +0 -5
  72. package/dist/ref/children.d.ts +0 -23
  73. package/dist/ref/element.d.ts +0 -49
  74. package/dist/render/array.d.ts +0 -21
  75. package/dist/render/directives.d.ts +0 -1
  76. package/dist/render/dynamic.d.ts +0 -2
  77. package/dist/render/injector.d.ts +0 -15
  78. package/dist/render/struct.d.ts +0 -85
  79. package/dist/render/template.d.ts +0 -5
  80. package/dist/state/array.d.ts +0 -22
  81. package/dist/state/object.d.ts +0 -31
  82. package/dist/types/render.d.ts +0 -5
  83. package/dist/types/utils.d.ts +0 -1
  84. package/dist/types/warp.d.ts +0 -5
  85. package/dist/utils/checkers.d.ts +0 -1
  86. package/dist/utils/name.d.ts +0 -2
  87. package/dist/utils/oberve.d.ts +0 -1
@@ -0,0 +1,69 @@
1
+ import { RumiousTemplate } from '../types/index.js';
2
+ import { RumiousRenderContext, render ,RumiousViewControl,createViewControl} from '../render/index.js';
3
+ import { RumiousApp } from '../app/index.js';
4
+
5
+ export class RumiousComponent < T = any > {
6
+ public props!: T;
7
+ public app!: RumiousApp;
8
+ public element!: HTMLElement;
9
+ public context!: RumiousRenderContext;
10
+ static tagName = 'rumious-component';
11
+
12
+ constructor() {}
13
+
14
+ createViewControl():RumiousViewControl{
15
+ return createViewControl();
16
+ }
17
+
18
+ mountTo(
19
+ template: RumiousTemplate,
20
+ target: HTMLElement,
21
+ ): HTMLElement {
22
+ return render(
23
+ template,
24
+ target,
25
+ this.context
26
+ );
27
+ }
28
+
29
+ prepare(
30
+ props: T,
31
+ context: RumiousRenderContext,
32
+ element: HTMLElement
33
+ ) {
34
+ this.app = context.app;
35
+ this.element = element;
36
+ this.props = props;
37
+ this.context = new RumiousRenderContext(
38
+ context.app,
39
+ this
40
+ );
41
+ }
42
+
43
+ template(): RumiousTemplate {
44
+ throw new Error(`RumiousRenderError: Cannot render empty component !`);
45
+ }
46
+
47
+ requestRender() {
48
+ let template = this.template();
49
+ render(
50
+ template,
51
+ this.element,
52
+ this.context
53
+ );
54
+ }
55
+
56
+ remove() {
57
+ this.element.remove();
58
+ }
59
+
60
+ onCreate() {}
61
+ onRender() {}
62
+ onDestroy() {}
63
+ beforeRender() {}
64
+
65
+ }
66
+
67
+ export class Fragment extends RumiousComponent<any>{
68
+
69
+ }
@@ -0,0 +1,76 @@
1
+ import { RumiousComponentConstructor } from '../types/index.js';
2
+ import { RumiousRenderContext } from '../render/index.js';
3
+ import type { RumiousComponent } from './component.js';
4
+
5
+
6
+ export class RumiousComponentElement < T > extends HTMLElement {
7
+ public component!: RumiousComponentConstructor < T > ;
8
+ public props!: T;
9
+ public context!: RumiousRenderContext;
10
+ public instance!: RumiousComponent;
11
+ constructor() {
12
+ super()
13
+ }
14
+
15
+ setContext(context: RumiousRenderContext){
16
+ this.context = context;
17
+ }
18
+
19
+ async connectedCallback() {
20
+ let instance = new this.component();
21
+ this.instance = instance;
22
+ instance.prepare(
23
+ this.props,
24
+ this.context,
25
+ this
26
+ );
27
+ instance.onCreate();
28
+ await instance.beforeRender();
29
+ instance.requestRender();
30
+ instance.onRender();
31
+ }
32
+
33
+ disconnectedCallback() {
34
+ this.instance.onDestroy();
35
+ }
36
+ }
37
+
38
+ export function createComponentElement < T > (
39
+ context: RumiousRenderContext,
40
+ component: RumiousComponentConstructor < T > ,
41
+ props: T
42
+ ): HTMLElement {
43
+ if (!window.customElements.get(component.tagName)) {
44
+ window.customElements.define(component.tagName, class extends RumiousComponentElement < T > {
45
+ constructor() {
46
+ super()
47
+ this.component = component;
48
+ this.props = props;
49
+ this.context = context;
50
+ }
51
+ });
52
+ }
53
+
54
+ let element = document.createElement(component.tagName);
55
+ return element;
56
+
57
+ }
58
+
59
+ export function renderComponent < T > (
60
+ component: RumiousComponentConstructor < T > ,
61
+ props: T
62
+ ): HTMLElement {
63
+ if (!window.customElements.get(component.tagName)) {
64
+ window.customElements.define(component.tagName, class extends RumiousComponentElement < T > {
65
+ constructor() {
66
+ super()
67
+ this.component = component;
68
+ this.props = props;
69
+ }
70
+ });
71
+ }
72
+
73
+ let element = document.createElement(component.tagName);
74
+ return element;
75
+
76
+ }
@@ -0,0 +1,2 @@
1
+ export * from './component.js';
2
+ export * from './element.js';
package/src/global.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type * as JSXUtils from './jsx/index.js';
2
+ import type { RumiousTemplate } from './types/index.js';
3
+
4
+ export {};
5
+
6
+ declare global {
7
+ var RUMIOUS: typeof JSXUtils;
8
+
9
+ namespace JSX {
10
+ type Element = RumiousTemplate;
11
+
12
+ interface IntrinsicElements {
13
+ [tagName: string]: any;
14
+ }
15
+
16
+ interface ElementChildrenAttribute {
17
+ children: {};
18
+ }
19
+ }
20
+ }
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ import './global.js';
2
+
3
+
4
+ export const __version__ = "2.x";
5
+ export * from './app/index.js';
6
+ export * from './types/index.js';
7
+ export * from './render/index.js';
8
+ export * from './state/index.js';
9
+ export * from './component/index.js';
10
+ export * from './ref/index.js';
11
+ export * from './jsx/index.js';
12
+ export * from './module/index.js';
13
+
@@ -0,0 +1,17 @@
1
+ import { RumiousRenderContext } from '../render/index.js';
2
+ import { createComponentElement } from '../component/index.js';
3
+ import { RumiousComponentConstructor } from '../types/index.js';
4
+
5
+ export function createComponent<T>(
6
+ context: RumiousRenderContext,
7
+ component: RumiousComponentConstructor<T>,
8
+ props:T
9
+ ): HTMLElement {
10
+ let element = createComponentElement(
11
+ context,
12
+ component,
13
+ props
14
+ );
15
+
16
+ return element;
17
+ }
@@ -0,0 +1,87 @@
1
+ import { RumiousRenderContext } from '../render/index.js';
2
+ import { isTemplate } from '../utils/checker.js';
3
+ import { RumiousState } from '../state/index.js';
4
+ import { RumiousComponentElement } from '../component/index.js';
5
+
6
+
7
+ function handleReactiveNode(
8
+ node: Node,
9
+ value: RumiousState < Node > ,
10
+ context: RumiousRenderContext
11
+ ): Node {
12
+ let currentNode: Node = node;
13
+
14
+ const update = () => {
15
+ if (!document.contains(currentNode) && value.reactor) {
16
+ value.reactor.removeBinding(update);
17
+ return;
18
+ }
19
+
20
+ const newNode = value.value;
21
+ if (newNode instanceof RumiousComponentElement) {
22
+ newNode.setContext(context);
23
+ }
24
+
25
+ currentNode.parentNode?.replaceChild(newNode, currentNode);
26
+ currentNode = newNode;
27
+ };
28
+
29
+ context.onRendered.push(() => {
30
+ update();
31
+ if (!value.reactor) return;
32
+ value.reactor.addBinding(update);
33
+ });
34
+ return node;
35
+ }
36
+
37
+
38
+ function isPrimitive(value: unknown): value is(string | number | boolean | bigint | symbol | null | undefined) {
39
+ return value === null || (typeof value !== 'object' && typeof value !== 'function');
40
+ }
41
+
42
+ export function createDynamicValue(
43
+ context: RumiousRenderContext,
44
+ value: unknown
45
+ ): Node {
46
+ if (Array.isArray(value)) {
47
+ const fragment = document.createDocumentFragment();
48
+
49
+ for (const item of value) {
50
+ if (isTemplate(item)) {
51
+ const rendered = item(document.createDocumentFragment(), context);
52
+ fragment.appendChild(rendered);
53
+ } else if (isPrimitive(item)) {
54
+ if (item !== null && item !== undefined && item !== false) {
55
+ fragment.appendChild(document.createTextNode(String(item)));
56
+ }
57
+ }
58
+ }
59
+
60
+ return fragment;
61
+ }
62
+
63
+
64
+ if (isTemplate(value)) {
65
+ return value(document.createDocumentFragment(), context);
66
+ }
67
+
68
+ if (value instanceof RumiousState && value.value instanceof Node) {
69
+ return handleReactiveNode(document.createTextNode(''), value, context);
70
+ }
71
+
72
+ if (value instanceof RumiousState && value.reactor) {
73
+ let node = document.createTextNode('');
74
+ context.onRendered.push(() => {
75
+ node.textContent = String(value.get());
76
+ if (!value.reactor) return;
77
+ value.reactor.addBinding((commit) => node.textContent = String(commit.state.get()));
78
+ });
79
+ return node;
80
+ }
81
+
82
+ if (isPrimitive(value) && value !== null && value !== undefined && value !== false) {
83
+ return document.createTextNode(String(value));
84
+ }
85
+
86
+ return document.createTextNode('');
87
+ }
@@ -0,0 +1,77 @@
1
+
2
+ export function appendChild(
3
+ parent:HTMLElement,
4
+ node:Node | string
5
+ ){
6
+ if(typeof node === 'string') parent.appendChild(document.createTextNode(node))
7
+ else parent.appendChild(node);
8
+ }
9
+
10
+ export function element(
11
+ parent: HTMLElement,
12
+ tagName: string,
13
+ attrs ? : Record < string, any >
14
+ ): HTMLElement {
15
+ const el = document.createElement(tagName);
16
+
17
+ if (attrs) {
18
+ for (let key in attrs) {
19
+ el.setAttribute(key, attrs[key]);
20
+ }
21
+ }
22
+
23
+ parent.appendChild(el);
24
+ return el;
25
+ }
26
+
27
+
28
+ export function replaceNode(oldNode: Node, newNode: Node): void {
29
+ const parent = oldNode.parentNode;
30
+ if (parent) {
31
+ parent.replaceChild(newNode, oldNode);
32
+ } else {
33
+ console.warn('replaceNode: oldNode has no parent. Cannot replace.');
34
+ }
35
+ }
36
+
37
+
38
+
39
+ interface RumiousEventTarget extends HTMLElement {
40
+ __rumiousEvents ? : Record < string, (e: Event) => void > ;
41
+ }
42
+
43
+ export function createEvent(
44
+ target: RumiousEventTarget,
45
+ name: string,
46
+ callback: (e: Event) => void
47
+ ) {
48
+ if (!target.__rumiousEvents) {
49
+ target.__rumiousEvents = {};
50
+ }
51
+ target.__rumiousEvents[name] = callback;
52
+ }
53
+
54
+ function triggerEvent(name: string, event: Event) {
55
+ const path = (event.composedPath?.() ?? [event.target]) as EventTarget[];
56
+
57
+ for (const target of path) {
58
+ if (
59
+ target instanceof HTMLElement &&
60
+ '__rumiousEvents' in target
61
+ ) {
62
+ const element = target as RumiousEventTarget;
63
+
64
+ const handler = element.__rumiousEvents?.[name];
65
+ if (handler) {
66
+ handler(event);
67
+ break;
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ export function delegateEvents(events: string[]) {
74
+ for (const name of events) {
75
+ window.addEventListener(name, (e) => triggerEvent(name, e));
76
+ }
77
+ }
@@ -0,0 +1,7 @@
1
+ export * from './element.js';
2
+ export * from './dynamic.js';
3
+ export * from './template.js';
4
+ export * from './component.js';
5
+
6
+
7
+