rumious 2.0.0 → 2.0.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.
@@ -6,6 +6,7 @@ export declare class RumiousComponent<T = any> {
6
6
  app: RumiousApp;
7
7
  element: HTMLElement;
8
8
  context: RumiousRenderContext;
9
+ slot: RumiousTemplate | null;
9
10
  static tagName: string;
10
11
  constructor();
11
12
  createViewControl(): RumiousViewControl;
@@ -1,4 +1,4 @@
1
- import { RumiousComponentConstructor } from '../types/index.js';
1
+ import { RumiousComponentConstructor, RumiousTemplate } from '../types/index.js';
2
2
  import { RumiousRenderContext } from '../render/index.js';
3
3
  import type { RumiousComponent } from './component.js';
4
4
  export declare class RumiousComponentElement<T> extends HTMLElement {
@@ -6,10 +6,12 @@ export declare class RumiousComponentElement<T> extends HTMLElement {
6
6
  props: T;
7
7
  context: RumiousRenderContext;
8
8
  instance: RumiousComponent;
9
+ slotTempl: RumiousTemplate | null;
9
10
  constructor();
10
11
  setContext(context: RumiousRenderContext): void;
11
12
  connectedCallback(): Promise<void>;
12
13
  disconnectedCallback(): void;
14
+ setSlot(templ: RumiousTemplate): void;
13
15
  }
14
- export declare function createComponentElement<T>(context: RumiousRenderContext, component: RumiousComponentConstructor<T>, props: T): HTMLElement;
16
+ export declare function createComponentElement<T>(context: RumiousRenderContext, component: RumiousComponentConstructor<T>, props: T): [HTMLElement];
15
17
  export declare function renderComponent<T>(component: RumiousComponentConstructor<T>, props: T): HTMLElement;
package/dist/index.js CHANGED
@@ -407,6 +407,7 @@ class RumiousComponent {
407
407
  app;
408
408
  element;
409
409
  context;
410
+ slot = null;
410
411
  static tagName = 'rumious-component';
411
412
  constructor() { }
412
413
  createViewControl() {
@@ -444,6 +445,7 @@ class RumiousComponentElement extends HTMLElement {
444
445
  props;
445
446
  context;
446
447
  instance;
448
+ slotTempl = null;
447
449
  constructor() {
448
450
  super();
449
451
  }
@@ -453,6 +455,7 @@ class RumiousComponentElement extends HTMLElement {
453
455
  async connectedCallback() {
454
456
  let instance = new this.component();
455
457
  this.instance = instance;
458
+ this.instance.slot = this.slotTempl;
456
459
  instance.prepare(this.props, this.context, this);
457
460
  instance.onCreate();
458
461
  await instance.beforeRender();
@@ -462,32 +465,29 @@ class RumiousComponentElement extends HTMLElement {
462
465
  disconnectedCallback() {
463
466
  this.instance.onDestroy();
464
467
  }
468
+ setSlot(templ) {
469
+ this.slotTempl = templ;
470
+ }
465
471
  }
466
472
  function createComponentElement(context, component, props) {
467
473
  if (!window.customElements.get(component.tagName)) {
468
474
  window.customElements.define(component.tagName, class extends RumiousComponentElement {
469
- constructor() {
470
- super();
471
- this.component = component;
472
- this.props = props;
473
- this.context = context;
474
- }
475
475
  });
476
476
  }
477
- let element = document.createElement(component.tagName);
478
- return element;
477
+ const element = document.createElement(component.tagName);
478
+ element.component = component;
479
+ element.props = props;
480
+ element.context = context;
481
+ return [element];
479
482
  }
480
483
  function renderComponent(component, props) {
481
484
  if (!window.customElements.get(component.tagName)) {
482
485
  window.customElements.define(component.tagName, class extends RumiousComponentElement {
483
- constructor() {
484
- super();
485
- this.component = component;
486
- this.props = props;
487
- }
488
486
  });
489
487
  }
490
- let element = document.createElement(component.tagName);
488
+ const element = document.createElement(component.tagName);
489
+ element.component = component;
490
+ element.props = props;
491
491
  return element;
492
492
  }
493
493
 
@@ -645,9 +645,14 @@ function appendChild(parent, node) {
645
645
  parent.appendChild(node);
646
646
  }
647
647
  function element(parent, tagName, attrs) {
648
- let element = document.createElement(tagName);
649
- parent.appendChild(element);
650
- return element;
648
+ const el = document.createElement(tagName);
649
+ if (attrs) {
650
+ for (let key in attrs) {
651
+ el.setAttribute(key, attrs[key]);
652
+ }
653
+ }
654
+ parent.appendChild(el);
655
+ return el;
651
656
  }
652
657
  function replaceNode(oldNode, newNode) {
653
658
  const parent = oldNode.parentNode;
@@ -1024,9 +1029,10 @@ const directives = {
1024
1029
  }
1025
1030
  };
1026
1031
 
1027
- function createComponent(context, component, props) {
1028
- let element = createComponentElement(context, component, props);
1029
- return element;
1032
+ function createComponent(root, context, component, props) {
1033
+ let [element] = createComponentElement(context, component, props);
1034
+ root.appendChild(element);
1035
+ return [element];
1030
1036
  }
1031
1037
 
1032
1038
  class RumiousModule {
@@ -1,3 +1,3 @@
1
1
  import { RumiousRenderContext } from '../render/index.js';
2
2
  import { RumiousComponentConstructor } from '../types/index.js';
3
- export declare function createComponent<T>(context: RumiousRenderContext, component: RumiousComponentConstructor<T>, props: T): HTMLElement;
3
+ export declare function createComponent<T>(root: HTMLElement, context: RumiousRenderContext, component: RumiousComponentConstructor<T>, props: T): [HTMLElement];
@@ -1,5 +1,5 @@
1
1
  export declare function appendChild(parent: HTMLElement, node: Node | string): void;
2
- export declare function element(parent: HTMLElement, tagName: string, attrs: Record<string, any>): HTMLElement;
2
+ export declare function element(parent: HTMLElement, tagName: string, attrs?: Record<string, any>): HTMLElement;
3
3
  export declare function replaceNode(oldNode: Node, newNode: Node): void;
4
4
  interface RumiousEventTarget extends HTMLElement {
5
5
  __rumiousEvents?: Record<string, (e: Event) => void>;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "rumious",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js",
10
- "require": "./dist/index.cjs.js"
10
+ "default": "./dist/index.js"
11
11
  }
12
12
  },
13
13
  "scripts": {
@@ -25,6 +25,9 @@
25
25
  "frontend",
26
26
  "framework"
27
27
  ],
28
+ "files":[
29
+ "dist/**"
30
+ ],
28
31
  "author": "smtdfc",
29
32
  "license": "MIT",
30
33
  "devDependencies": {},
package/rollup.config.js DELETED
@@ -1,21 +0,0 @@
1
- import typescript from '@rollup/plugin-typescript';
2
-
3
- const isProduction = process.env.NODE_ENV === 'production';
4
-
5
- export default {
6
- input: 'src/index.ts',
7
- external: ['rumious-compiler'],
8
- output: {
9
- file: './dist/index.js',
10
- format: 'esm',
11
- sourcemap: false,
12
- paths: {
13
- 'rumious-compiler': !isProduction
14
- ? '../compiler/dist/index.js'
15
- : 'rumious-compiler'
16
- }
17
- },
18
- plugins: [
19
- typescript({ tsconfig: './tsconfig.json' })
20
- ]
21
- };
package/src/app/app.ts DELETED
@@ -1,45 +0,0 @@
1
- import { RumiousRenderContext, render } from '../render/index.js';
2
- import { RumiousTemplate } from '../types/index.js';
3
- import { RumiousModule, RumiousModuleClass } from '../module/index.js';
4
-
5
- export interface RumiousAppConfig {
6
- root: HTMLElement;
7
- }
8
-
9
- export class RumiousApp {
10
- public modules: any[] = [];
11
-
12
- public context: RumiousRenderContext = new RumiousRenderContext(
13
- this,
14
- this
15
- );
16
-
17
- constructor(
18
- public config: RumiousAppConfig
19
- ) {}
20
-
21
- addModule < T extends RumiousModule, O > (
22
- ModuleClass: RumiousModuleClass < T, O > ,
23
- options ? : O
24
- ): T {
25
- const instance = ModuleClass.init(this, options);
26
- this.modules.push(instance);
27
- return instance;
28
- }
29
-
30
- render(
31
- content: RumiousTemplate
32
- ): void {
33
- render(
34
- content,
35
- this.config.root,
36
- this.context
37
- );
38
- }
39
- }
40
-
41
- export function createApp(
42
- config: RumiousAppConfig
43
- ): RumiousApp {
44
- return new RumiousApp(config);
45
- }
package/src/app/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './app.js';
@@ -1,69 +0,0 @@
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
- }
@@ -1,76 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export * from './component.js';
2
- export * from './element.js';
package/src/global.ts DELETED
@@ -1,20 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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
-
@@ -1,17 +0,0 @@
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
- }
@@ -1,87 +0,0 @@
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
- }
@@ -1,70 +0,0 @@
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
- let element = document.createElement(tagName);
16
- parent.appendChild(element);
17
- return element;
18
- }
19
-
20
-
21
- export function replaceNode(oldNode: Node, newNode: Node): void {
22
- const parent = oldNode.parentNode;
23
- if (parent) {
24
- parent.replaceChild(newNode, oldNode);
25
- } else {
26
- console.warn('replaceNode: oldNode has no parent. Cannot replace.');
27
- }
28
- }
29
-
30
-
31
-
32
- interface RumiousEventTarget extends HTMLElement {
33
- __rumiousEvents ? : Record < string, (e: Event) => void > ;
34
- }
35
-
36
- export function createEvent(
37
- target: RumiousEventTarget,
38
- name: string,
39
- callback: (e: Event) => void
40
- ) {
41
- if (!target.__rumiousEvents) {
42
- target.__rumiousEvents = {};
43
- }
44
- target.__rumiousEvents[name] = callback;
45
- }
46
-
47
- function triggerEvent(name: string, event: Event) {
48
- const path = (event.composedPath?.() ?? [event.target]) as EventTarget[];
49
-
50
- for (const target of path) {
51
- if (
52
- target instanceof HTMLElement &&
53
- '__rumiousEvents' in target
54
- ) {
55
- const element = target as RumiousEventTarget;
56
-
57
- const handler = element.__rumiousEvents?.[name];
58
- if (handler) {
59
- handler(event);
60
- break;
61
- }
62
- }
63
- }
64
- }
65
-
66
- export function delegateEvents(events: string[]) {
67
- for (const name of events) {
68
- window.addEventListener(name, (e) => triggerEvent(name, e));
69
- }
70
- }
package/src/jsx/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './element.js';
2
- export * from './dynamic.js';
3
- export * from './template.js';
4
- export * from './component.js';
5
-
6
-
7
-