ouider 0.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.
@@ -0,0 +1,267 @@
1
+ declare class Emits<O extends Record<string, any>> {
2
+ private events;
3
+ constructor(events: O);
4
+ emit(event: keyof O, ...args: any): void;
5
+ }
6
+
7
+ type StateWatcher<T> = <K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]) => void;
8
+ declare class Stated<T> {
9
+ value: T;
10
+ constructor(value: T);
11
+ }
12
+ declare function isStated<T>(ob: any): ob is Stated<T>;
13
+ declare function stated<S, T>(target: T, state: State<S>): Stated<T>;
14
+ declare class State<T extends Record<string, any>> {
15
+ private THRESHOLD_TIME;
16
+ private debounceTime;
17
+ private state;
18
+ private listeners;
19
+ private timer;
20
+ constructor(data: T);
21
+ wrap<T>(obj: T): Stated<T>;
22
+ has(key: keyof T): boolean;
23
+ setValue(key: keyof T, value: any): void;
24
+ getValue(key: keyof T): any;
25
+ get value(): T;
26
+ private dispatchChanges;
27
+ didChange(path: keyof T, oldValue: any, newValue: any): void;
28
+ watch(listener: StateWatcher<T>): number;
29
+ unwatch(listener: StateWatcher<T> | number): void;
30
+ }
31
+
32
+ type ComponentProps<K extends Record<string, any>> = K;
33
+ declare function Component(options: {
34
+ template: string;
35
+ tag: string;
36
+ use?: OComponentType[];
37
+ css?: string;
38
+ }): <T extends {
39
+ new (...args: any[]): {};
40
+ }>(constructor: T) => {
41
+ new (...args: any[]): {
42
+ template: string;
43
+ css: string;
44
+ };
45
+ } & T;
46
+ interface Component<P extends Record<string, any>, O extends Record<string, any>> {
47
+ state: State<any>;
48
+ readonly emits: Emits<O>;
49
+ readonly props: ComponentProps<P>;
50
+ onMounted(): void;
51
+ willMount(): void;
52
+ willUnmount(): void;
53
+ provide<T>(key: string, value: T): void;
54
+ inject<T>(key: string): T | undefined;
55
+ }
56
+ interface ComponentConstructor<P extends Record<string, any>, O extends Record<string, any>> {
57
+ new (props?: P, emits?: O): Component<P, O>;
58
+ }
59
+ declare function createComponent<P extends Record<string, any>, O extends Record<string, any>>(ctr: ComponentConstructor<P, O>, props?: P, emits?: O): Component<P, O>;
60
+ declare class OComponent<P extends Record<string, any> = {}, O extends Record<string, any> = {}> implements Component<P, O> {
61
+ state: State<any>;
62
+ private parent?;
63
+ readonly emits: Emits<O>;
64
+ readonly props: ComponentProps<P>;
65
+ private provides;
66
+ constructor(props?: P, emits?: O);
67
+ onMounted(): void;
68
+ willMount(): void;
69
+ willUnmount(): void;
70
+ /** Provide a value for descendants */
71
+ provide<T>(key: string, value: T): void;
72
+ /** Inject a value from nearest ancestor */
73
+ inject<T>(key: string): T | undefined;
74
+ }
75
+ type LazyLoader<P extends Record<string, any>, O extends Record<string, any>> = () => Promise<{
76
+ default: ComponentConstructor<P, O>;
77
+ }>;
78
+ type OComponentType<P extends Record<string, any> = {}, O extends Record<string, any> = {}> = ComponentConstructor<P, O> | LazyLoader<P, O>;
79
+
80
+ type ProvideFunction<T> = () => T;
81
+ type Provider<T = any> = {
82
+ value?: T;
83
+ provide?: ProvideFunction<T>;
84
+ };
85
+ interface Plugin {
86
+ install(app: App): void;
87
+ }
88
+ /** Injection token key */
89
+ type InjectionKey = string;
90
+ /** Providers type */
91
+ type Providers = Map<InjectionKey, Provider>;
92
+ /**
93
+ * OUIDesigner App
94
+ */
95
+ declare class App {
96
+ private root;
97
+ static currentApp: App | null;
98
+ private providers;
99
+ /**
100
+ * Provide a value through a key to all the app globally
101
+ * @param token the registration key
102
+ * @param value the provider value
103
+ */
104
+ provide<T>(token: InjectionKey, value: T | (() => T)): void;
105
+ /**
106
+ * Get globally a provider through a given key
107
+ * @param token the key to look up globally
108
+ * @returns a provider value
109
+ */
110
+ inject<T>(token: InjectionKey): T;
111
+ /**
112
+ * Register a plugin to be used by this app
113
+ * @param plugin the plugin to register
114
+ * @returns `this` App instance
115
+ */
116
+ use(plugin: Plugin): this;
117
+ private host;
118
+ constructor(root: ComponentConstructor<any, any>);
119
+ /**
120
+ * Mount the App in a host element
121
+ * @param selector the host element where the app's root component should be mounted
122
+ */
123
+ mount(selector: string): void;
124
+ }
125
+ /**
126
+ * Provide a value through a key to all the app globally
127
+ * @param token the registration key
128
+ * @param value the provider value
129
+ */
130
+ declare function provide<T>(token: InjectionKey, value: T | (() => T)): void;
131
+ /**
132
+ * Get globally a provider through a given key
133
+ * @param token the key to look up globally
134
+ * @returns a provider value
135
+ */
136
+ declare function inject<T>(token: InjectionKey): T;
137
+
138
+ declare class RenderContext {
139
+ private app;
140
+ component: OComponent;
141
+ private parentContext;
142
+ static PROVIDE_TOKEN: string;
143
+ private bindings;
144
+ private directives;
145
+ private mountedComponents;
146
+ stack: Record<string, any>[];
147
+ constructor(app: App, component: OComponent, parentContext: RenderContext | null, ...frames: Record<string, any>[]);
148
+ get hostElement(): HTMLElement;
149
+ bind(binding: Binding): void;
150
+ directive(directive: Directive): void;
151
+ evaluateExpression(expr: string): boolean;
152
+ resolve(key: string, strict?: boolean, ...additionFrames: Record<string, any>[]): any;
153
+ /**
154
+ * Handing (o-model) like (ngModel) update, we should support mutliple syntaxe like o-mode="value" where value is defined directly on the component
155
+ * o-model="data['key']" where data is either defined on the component, of in the enclosing scope in case of for-loop for instance
156
+ * */
157
+ updateValue(key: string, value: any): void;
158
+ push(frame: Record<string, any>): void;
159
+ pop(): void;
160
+ updateBindings(): void;
161
+ updateBinding(binding: Binding): void;
162
+ updateDirectives(): void;
163
+ private render;
164
+ private expandClass;
165
+ private expandStyle;
166
+ private expandStandardAttributes;
167
+ handleElementNode(node: HTMLElement): void;
168
+ handleTextNode(node: HTMLElement): void;
169
+ private componentAttributes;
170
+ mountComponent<T, O>(hostNode: HTMLElement, component: OComponentType<T, O>, parentContext: RenderContext, props?: Record<string, {
171
+ name: string;
172
+ value: any;
173
+ expr?: string;
174
+ }>, emits?: O): Promise<void>;
175
+ unmountComponent(node: Element): void;
176
+ static h<P, O>(component: ComponentConstructor<P, O>, props: P, emits?: O): OComponent<P>;
177
+ static h<P, O>(component: OComponentType<P>, props: P, emits?: O): Promise<OComponent<P>>;
178
+ }
179
+ type Binding = {
180
+ type: 'model' | 'interpolation' | 'attribute' | 'prop';
181
+ node: HTMLElement;
182
+ key: string;
183
+ template?: string | null;
184
+ context: RenderContext;
185
+ };
186
+ type Directive = {
187
+ type: 'if' | 'for';
188
+ node: HTMLElement;
189
+ expr?: string;
190
+ placeholder: Comment;
191
+ context: RenderContext;
192
+ active?: boolean;
193
+ list?: string;
194
+ item?: string;
195
+ children?: Map<any, {
196
+ node: ChildNode;
197
+ ctx: RenderContext;
198
+ }>;
199
+ key?: string;
200
+ };
201
+
202
+ /**
203
+ * Component responsible for display routes
204
+ * Usage: <o-router></o-router>
205
+ */
206
+ declare class RouterComponent extends OComponent {
207
+ private routeStateHander;
208
+ private router;
209
+ willMount(): void;
210
+ onMounted(): void;
211
+ willUnmount(): void;
212
+ }
213
+ declare const ROUTER_INJECTION_TOKEN = "OROUTER_TOKEN";
214
+ declare const ACTIVE_ROUTE_TOKEN = "ACTIVE_ROUTE";
215
+ interface Route {
216
+ path?: string;
217
+ name: string;
218
+ component?: OComponentType;
219
+ redirectTo?: string;
220
+ }
221
+ declare function useRouter(): Router;
222
+ declare function createRouter(routes: Routes): Router;
223
+ type Routes = Array<Route>;
224
+ type MatchedRoute = {
225
+ route: Route;
226
+ params: Record<string, any>;
227
+ query: Record<string, string>;
228
+ };
229
+ type Promised<T> = T | Promise<T>;
230
+ type RouteLocationNamed = {
231
+ name: string;
232
+ params?: Record<string, any>;
233
+ };
234
+ type RouteGuardReturn = void | boolean | RouteLocationNamed;
235
+ type RouteGaurdFunction = (to: {
236
+ url: string;
237
+ path: string;
238
+ name: string;
239
+ }, from?: {
240
+ query: Record<string, string>;
241
+ params: Record<string, string>;
242
+ }) => Promised<RouteGuardReturn>;
243
+ interface RouteGuard {
244
+ type: 'before' | 'after';
245
+ fn: RouteGaurdFunction;
246
+ }
247
+ declare class Router implements Plugin {
248
+ routes: Routes;
249
+ private guards;
250
+ constructor(routes: Routes);
251
+ install(app: App): void;
252
+ resolve(path: string): MatchedRoute;
253
+ push(options: {
254
+ name?: string;
255
+ path?: string;
256
+ params?: Record<string, string>;
257
+ absolute?: boolean;
258
+ }): void;
259
+ private beforeRouteGoing;
260
+ private afterRouteGoing;
261
+ bind(component: RouterComponent): (() => void);
262
+ unbind(handler: () => void): void;
263
+ beforeEach(fn: RouteGaurdFunction): (() => void);
264
+ afterEach(fn: RouteGaurdFunction): (() => void);
265
+ }
266
+
267
+ export { ACTIVE_ROUTE_TOKEN, App, type Binding, Component, type ComponentConstructor, type ComponentProps, type Directive, Emits, type InjectionKey, type LazyLoader, OComponent, type OComponentType, type Plugin, type Promised, type Provider, type Providers, ROUTER_INJECTION_TOKEN, RenderContext, type Route, type RouteGaurdFunction, type RouteGuard, type RouteGuardReturn, type RouteLocationNamed, Router, RouterComponent, type Routes, State, type StateWatcher, Stated, createComponent, createRouter, inject, isStated, provide, stated, useRouter };
@@ -0,0 +1,267 @@
1
+ declare class Emits<O extends Record<string, any>> {
2
+ private events;
3
+ constructor(events: O);
4
+ emit(event: keyof O, ...args: any): void;
5
+ }
6
+
7
+ type StateWatcher<T> = <K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]) => void;
8
+ declare class Stated<T> {
9
+ value: T;
10
+ constructor(value: T);
11
+ }
12
+ declare function isStated<T>(ob: any): ob is Stated<T>;
13
+ declare function stated<S, T>(target: T, state: State<S>): Stated<T>;
14
+ declare class State<T extends Record<string, any>> {
15
+ private THRESHOLD_TIME;
16
+ private debounceTime;
17
+ private state;
18
+ private listeners;
19
+ private timer;
20
+ constructor(data: T);
21
+ wrap<T>(obj: T): Stated<T>;
22
+ has(key: keyof T): boolean;
23
+ setValue(key: keyof T, value: any): void;
24
+ getValue(key: keyof T): any;
25
+ get value(): T;
26
+ private dispatchChanges;
27
+ didChange(path: keyof T, oldValue: any, newValue: any): void;
28
+ watch(listener: StateWatcher<T>): number;
29
+ unwatch(listener: StateWatcher<T> | number): void;
30
+ }
31
+
32
+ type ComponentProps<K extends Record<string, any>> = K;
33
+ declare function Component(options: {
34
+ template: string;
35
+ tag: string;
36
+ use?: OComponentType[];
37
+ css?: string;
38
+ }): <T extends {
39
+ new (...args: any[]): {};
40
+ }>(constructor: T) => {
41
+ new (...args: any[]): {
42
+ template: string;
43
+ css: string;
44
+ };
45
+ } & T;
46
+ interface Component<P extends Record<string, any>, O extends Record<string, any>> {
47
+ state: State<any>;
48
+ readonly emits: Emits<O>;
49
+ readonly props: ComponentProps<P>;
50
+ onMounted(): void;
51
+ willMount(): void;
52
+ willUnmount(): void;
53
+ provide<T>(key: string, value: T): void;
54
+ inject<T>(key: string): T | undefined;
55
+ }
56
+ interface ComponentConstructor<P extends Record<string, any>, O extends Record<string, any>> {
57
+ new (props?: P, emits?: O): Component<P, O>;
58
+ }
59
+ declare function createComponent<P extends Record<string, any>, O extends Record<string, any>>(ctr: ComponentConstructor<P, O>, props?: P, emits?: O): Component<P, O>;
60
+ declare class OComponent<P extends Record<string, any> = {}, O extends Record<string, any> = {}> implements Component<P, O> {
61
+ state: State<any>;
62
+ private parent?;
63
+ readonly emits: Emits<O>;
64
+ readonly props: ComponentProps<P>;
65
+ private provides;
66
+ constructor(props?: P, emits?: O);
67
+ onMounted(): void;
68
+ willMount(): void;
69
+ willUnmount(): void;
70
+ /** Provide a value for descendants */
71
+ provide<T>(key: string, value: T): void;
72
+ /** Inject a value from nearest ancestor */
73
+ inject<T>(key: string): T | undefined;
74
+ }
75
+ type LazyLoader<P extends Record<string, any>, O extends Record<string, any>> = () => Promise<{
76
+ default: ComponentConstructor<P, O>;
77
+ }>;
78
+ type OComponentType<P extends Record<string, any> = {}, O extends Record<string, any> = {}> = ComponentConstructor<P, O> | LazyLoader<P, O>;
79
+
80
+ type ProvideFunction<T> = () => T;
81
+ type Provider<T = any> = {
82
+ value?: T;
83
+ provide?: ProvideFunction<T>;
84
+ };
85
+ interface Plugin {
86
+ install(app: App): void;
87
+ }
88
+ /** Injection token key */
89
+ type InjectionKey = string;
90
+ /** Providers type */
91
+ type Providers = Map<InjectionKey, Provider>;
92
+ /**
93
+ * OUIDesigner App
94
+ */
95
+ declare class App {
96
+ private root;
97
+ static currentApp: App | null;
98
+ private providers;
99
+ /**
100
+ * Provide a value through a key to all the app globally
101
+ * @param token the registration key
102
+ * @param value the provider value
103
+ */
104
+ provide<T>(token: InjectionKey, value: T | (() => T)): void;
105
+ /**
106
+ * Get globally a provider through a given key
107
+ * @param token the key to look up globally
108
+ * @returns a provider value
109
+ */
110
+ inject<T>(token: InjectionKey): T;
111
+ /**
112
+ * Register a plugin to be used by this app
113
+ * @param plugin the plugin to register
114
+ * @returns `this` App instance
115
+ */
116
+ use(plugin: Plugin): this;
117
+ private host;
118
+ constructor(root: ComponentConstructor<any, any>);
119
+ /**
120
+ * Mount the App in a host element
121
+ * @param selector the host element where the app's root component should be mounted
122
+ */
123
+ mount(selector: string): void;
124
+ }
125
+ /**
126
+ * Provide a value through a key to all the app globally
127
+ * @param token the registration key
128
+ * @param value the provider value
129
+ */
130
+ declare function provide<T>(token: InjectionKey, value: T | (() => T)): void;
131
+ /**
132
+ * Get globally a provider through a given key
133
+ * @param token the key to look up globally
134
+ * @returns a provider value
135
+ */
136
+ declare function inject<T>(token: InjectionKey): T;
137
+
138
+ declare class RenderContext {
139
+ private app;
140
+ component: OComponent;
141
+ private parentContext;
142
+ static PROVIDE_TOKEN: string;
143
+ private bindings;
144
+ private directives;
145
+ private mountedComponents;
146
+ stack: Record<string, any>[];
147
+ constructor(app: App, component: OComponent, parentContext: RenderContext | null, ...frames: Record<string, any>[]);
148
+ get hostElement(): HTMLElement;
149
+ bind(binding: Binding): void;
150
+ directive(directive: Directive): void;
151
+ evaluateExpression(expr: string): boolean;
152
+ resolve(key: string, strict?: boolean, ...additionFrames: Record<string, any>[]): any;
153
+ /**
154
+ * Handing (o-model) like (ngModel) update, we should support mutliple syntaxe like o-mode="value" where value is defined directly on the component
155
+ * o-model="data['key']" where data is either defined on the component, of in the enclosing scope in case of for-loop for instance
156
+ * */
157
+ updateValue(key: string, value: any): void;
158
+ push(frame: Record<string, any>): void;
159
+ pop(): void;
160
+ updateBindings(): void;
161
+ updateBinding(binding: Binding): void;
162
+ updateDirectives(): void;
163
+ private render;
164
+ private expandClass;
165
+ private expandStyle;
166
+ private expandStandardAttributes;
167
+ handleElementNode(node: HTMLElement): void;
168
+ handleTextNode(node: HTMLElement): void;
169
+ private componentAttributes;
170
+ mountComponent<T, O>(hostNode: HTMLElement, component: OComponentType<T, O>, parentContext: RenderContext, props?: Record<string, {
171
+ name: string;
172
+ value: any;
173
+ expr?: string;
174
+ }>, emits?: O): Promise<void>;
175
+ unmountComponent(node: Element): void;
176
+ static h<P, O>(component: ComponentConstructor<P, O>, props: P, emits?: O): OComponent<P>;
177
+ static h<P, O>(component: OComponentType<P>, props: P, emits?: O): Promise<OComponent<P>>;
178
+ }
179
+ type Binding = {
180
+ type: 'model' | 'interpolation' | 'attribute' | 'prop';
181
+ node: HTMLElement;
182
+ key: string;
183
+ template?: string | null;
184
+ context: RenderContext;
185
+ };
186
+ type Directive = {
187
+ type: 'if' | 'for';
188
+ node: HTMLElement;
189
+ expr?: string;
190
+ placeholder: Comment;
191
+ context: RenderContext;
192
+ active?: boolean;
193
+ list?: string;
194
+ item?: string;
195
+ children?: Map<any, {
196
+ node: ChildNode;
197
+ ctx: RenderContext;
198
+ }>;
199
+ key?: string;
200
+ };
201
+
202
+ /**
203
+ * Component responsible for display routes
204
+ * Usage: <o-router></o-router>
205
+ */
206
+ declare class RouterComponent extends OComponent {
207
+ private routeStateHander;
208
+ private router;
209
+ willMount(): void;
210
+ onMounted(): void;
211
+ willUnmount(): void;
212
+ }
213
+ declare const ROUTER_INJECTION_TOKEN = "OROUTER_TOKEN";
214
+ declare const ACTIVE_ROUTE_TOKEN = "ACTIVE_ROUTE";
215
+ interface Route {
216
+ path?: string;
217
+ name: string;
218
+ component?: OComponentType;
219
+ redirectTo?: string;
220
+ }
221
+ declare function useRouter(): Router;
222
+ declare function createRouter(routes: Routes): Router;
223
+ type Routes = Array<Route>;
224
+ type MatchedRoute = {
225
+ route: Route;
226
+ params: Record<string, any>;
227
+ query: Record<string, string>;
228
+ };
229
+ type Promised<T> = T | Promise<T>;
230
+ type RouteLocationNamed = {
231
+ name: string;
232
+ params?: Record<string, any>;
233
+ };
234
+ type RouteGuardReturn = void | boolean | RouteLocationNamed;
235
+ type RouteGaurdFunction = (to: {
236
+ url: string;
237
+ path: string;
238
+ name: string;
239
+ }, from?: {
240
+ query: Record<string, string>;
241
+ params: Record<string, string>;
242
+ }) => Promised<RouteGuardReturn>;
243
+ interface RouteGuard {
244
+ type: 'before' | 'after';
245
+ fn: RouteGaurdFunction;
246
+ }
247
+ declare class Router implements Plugin {
248
+ routes: Routes;
249
+ private guards;
250
+ constructor(routes: Routes);
251
+ install(app: App): void;
252
+ resolve(path: string): MatchedRoute;
253
+ push(options: {
254
+ name?: string;
255
+ path?: string;
256
+ params?: Record<string, string>;
257
+ absolute?: boolean;
258
+ }): void;
259
+ private beforeRouteGoing;
260
+ private afterRouteGoing;
261
+ bind(component: RouterComponent): (() => void);
262
+ unbind(handler: () => void): void;
263
+ beforeEach(fn: RouteGaurdFunction): (() => void);
264
+ afterEach(fn: RouteGaurdFunction): (() => void);
265
+ }
266
+
267
+ export { ACTIVE_ROUTE_TOKEN, App, type Binding, Component, type ComponentConstructor, type ComponentProps, type Directive, Emits, type InjectionKey, type LazyLoader, OComponent, type OComponentType, type Plugin, type Promised, type Provider, type Providers, ROUTER_INJECTION_TOKEN, RenderContext, type Route, type RouteGaurdFunction, type RouteGuard, type RouteGuardReturn, type RouteLocationNamed, Router, RouterComponent, type Routes, State, type StateWatcher, Stated, createComponent, createRouter, inject, isStated, provide, stated, useRouter };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';var k=require('route-parser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var k__default=/*#__PURE__*/_interopDefault(k);var A=(s,e,t,n)=>{for(var o=e,c=s.length-1,i;c>=0;c--)(i=s[c])&&(o=(i(o))||o);return o};var T=class{constructor(e){this.events=e;}emit(e,...t){let n=this.events[e];n&&n(...t);}};var P=class{components=new Map;register(e,t){let n=e.toLocaleLowerCase();if(this.components.has(n)){console.warn(`[OUID] - ${n} component already registered`);return}console.debug("Registering new component: "+e,t),this.components.set(n,t);}unregister(e){let t=e.toLocaleLowerCase();this.components.delete(t);}get(e){return this.components.get(e.toLocaleLowerCase())}getAll(){return Array.from(this.components.entries())}},x=new P;var v=class{constructor(e){this.value=e;}};function E(s){return typeof s=="object"&&!Array.isArray(s)&&"value"in s&&s instanceof v}function B(s,e){let t=(n,o=new Map)=>{if(o.has(n))return o[n];let c=new Proxy(n,{set:(i,r,a)=>{let p=i[r];return typeof a=="object"?i[r]=t(a):i[r]=a,e.didChange(r,p,a),true},get:(i,r)=>Reflect.get(i,r)});o[n]=c;for(let i=n;i;i=Object.getPrototypeOf(i))Object.keys(i).forEach(r=>{let a=n[r];typeof a=="object"&&(n[r]=t(a,o));});return c};if(typeof s=="function")throw new Error("Can't create reactive element over a function");return typeof s!="object"&&typeof s!="symbol"?new Proxy(new v(s),{set:(n,o,c)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);let i=n[o];return n[o]=c,e.didChange(o,i,c),true},get:(n,o)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);return n[o]}}):new v(t(s))}var C=class{THRESHOLD_TIME=50;debounceTime=new Date().getTime();state;listeners=[];timer=null;constructor(e){this.state=new Proxy(e,{set:(t,n,o)=>{let c=t[n];return t[n]=o,this.didChange(n,c,o),true},get:(t,n)=>t[n]});}wrap(e){return B(e,this)}has(e){return e in this.state}setValue(e,t){this.state[e]=t;}getValue(e){return this.state[e]}get value(){return this.state}dispatchChanges(e,t,n){for(let o of this.listeners)o(e,t,n);}didChange(e,t,n){let o=Date.now();o-this.debounceTime<=this.THRESHOLD_TIME&&clearTimeout(this.timer),this.debounceTime=o,this.timer=setTimeout(()=>{this.dispatchChanges(e,t,n);},this.THRESHOLD_TIME);}watch(e){return this.listeners.push(e),this.listeners.length-1}unwatch(e){if(typeof e=="number"){this.listeners.splice(e,1);return}this.listeners.splice(this.listeners.indexOf(e),1);}};function _(s){return function(e){let t=class extends e{template=s.template;css=s.css};console.log("Construct",s.css);let n=t;return x.register(s.tag,n),t}}function b(s,e,t){return new s(e,t)}var O=class{state;parent=void 0;emits;props;provides=new Map;constructor(e={},t={}){this.state=new C(this),this.props=e,this.emits=new T(t);}onMounted(){}willMount(){}willUnmount(){}provide(e,t){this.provides.set(e,t);}inject(e){let t=this;for(;t;){if(t.provides.has(e))return t.provides.get(e);t=t.parent;}}};function N(s){let e=document.createElement("style");return console.log("css:",s),e.innerHTML=s,document.head.appendChild(e),e}function S(s){s&&document.head.removeChild(s);}function U(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function h(s){return E(s)?s.value:s}function F(s){let e={};for(let t=s;t;t=Object.getPrototypeOf(t))Object.getOwnPropertyNames(t).forEach(n=>{let o=s[n];typeof o=="function"&&n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")?n in e||(e[n]=o.bind(s)):n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")&&(n in e||(e[n]=o));});return e}function G(s){return typeof s=="function"&&!("prototype"in s)}var g=class s{constructor(e,t,n,...o){this.app=e;this.component=t;this.parentContext=n;for(let c of o)this.stack.push(c);}static PROVIDE_TOKEN="RENDER_CONTEXT";bindings=[];directives=[];mountedComponents=new WeakMap;stack=[];get hostElement(){return this.component._hostElement}bind(e){this.bindings.push(e);}directive(e){this.directives.push(e);}evaluateExpression(e){return this.resolve(e)}resolve(e,t=true,...n){let o=this.component.state.value,i={...F(o)};for(let r of [...this.stack.toReversed(),...n])Object.assign(i,r);try{let r=`${t?'"use strict";':""}return ${e};`,a=new Function(...Object.keys(i),r);return a.bind(this.component),a.apply(this.component,Object.values(i))}catch(r){console.log(this),console.error(r);}}updateValue(e,t){e.split(/[\.\[]/)[0]in this.component?this.resolve(`this.${e}=__o_model_value__`,true,{__o_model_value__:t}):this.resolve(`${e}=__o_model_value__`,true,{__o_model_value__:t}),this.component.state.didChange("","","");}push(e){this.stack.unshift(e);}pop(){this.stack.shift();}updateBindings(){this.bindings.forEach(e=>this.updateBinding(e));}updateBinding(e){if(e.type==="model")e.node.value=h(e.context.resolve(e.key));else if(e.type==="interpolation")e.node.textContent=e.template?.replace(/\{\{(.*?)\}\}/g,(t,n)=>(n=n.trim(),h(e.context.resolve(n))))??"";else if(e.type==="attribute"){let t=e.key,n=h(this.resolve(e.template));t==="class"?this.expandClass(e.node,n):t==="style"?this.expandStyle(e.node,n):typeof n!="object"&&typeof n!="function"&&typeof n!="symbol"&&typeof n<"u"&&e.node.setAttribute(t,n.toString());}else if(e.type==="prop"&&e.context.component){let t=h(this.resolve(e.template));try{console.log({...e.context.component}),e.context.component.props[e.key]=t,e.context.updateBindings(),e.context.updateDirectives();}catch(n){console.error(n);}}}updateDirectives(){for(let e of this.directives){if(e.type==="if"){let t=false;try{t=e.context.evaluateExpression(e.expr),E(t)&&(t=t.value);}catch(n){console.error("Error:",n);}t?e.active!==true&&(e.active=true,e.placeholder.after(e.node),e.context.render(e.node),e.context.updateBindings()):t||e.active!==false&&(this.unmountComponent(e.node),e.node.remove(),e.active=false);}if(e.type==="for"){console.log("Start for directive",e);let t=e.children??new Map,n=new Map,o=(r,a)=>e.key?h(e.context.resolve(e.key,true,{[e.item]:r})):a,c=h(e.context.resolve(e.list))||[];console.log("For-directive",c);let i=e.placeholder;c.forEach(async(r,a)=>{let p=o(r,a),d=t.get(p),l=d?.node,m={[e.item]:r},u=d?.ctx??new s(this.app,this.component,null);u.stack=[m,...e.context.stack],l?(u.updateBindings(),u.updateDirectives()):(l=e.node.cloneNode(true),u.render(l),i.after(l),u.updateBindings(),u.updateDirectives()),i=l,n.set(p,{node:l,ctx:u});}),t.forEach((r,a)=>{n.has(a)||(this.unmountComponent(r.node),r.node.remove());}),e.children=n;}}}render(e){switch(e.nodeType){case Node.TEXT_NODE:this.handleTextNode(e);break;case Node.ELEMENT_NODE:this.handleElementNode(e);break;default:console.warn("Unknown node",e);}}expandClass(e,t){let n=t;typeof t=="object"&&(Array.isArray(t)?n=t.join(" "):n=Object.keys(t).filter(o=>t[o]).join(" ")),e.setAttribute("class",n);}expandStyle(e,t){let n=t;typeof t=="object"&&!Array.isArray(t)&&(n=Object.keys(t).map(o=>`${o}: ${t[o]}`).join(";")),e.setAttribute("style",n);}expandStandardAttributes(e){[...e.attributes].filter(t=>t.name.startsWith(":")).filter(t=>[":id",":style",":class",":placeholder"].includes(t.name)).forEach(t=>{let n=t.name.substring(1);this.bind({type:"attribute",node:e,key:n,context:this,template:t.value.trim()}),e.removeAttribute(t.name);});}handleElementNode(e){let t=null;if(e.hasAttribute("o-if")){let r=e.getAttribute("o-if"),a=document.createComment("o-if:"+r);e.parentNode?.insertBefore(a,e),e.removeAttribute("o-if"),this.directive({type:"if",expr:r,node:e,placeholder:a,context:this,active:void 0}),t="if";}if(e.hasAttribute("o-for")){if(t==="if")throw new Error("Can't have o-if and o-for on the same component");let r=e.getAttribute("o-for"),[a,p]=r.split(" of ").map(m=>m.trim()),d=document.createComment("for:"+r),l=e.getAttribute(":key");e.parentNode?.insertBefore(d,e),e.removeAttribute("o-for"),e.removeAttribute(":key"),e.remove(),this.directive({type:"for",item:a,list:p,node:e,placeholder:d,context:this,key:l}),t="for";}t!=="for"&&[...e.attributes].forEach(r=>{if(r.name==="o-model"){let a=r.value.trim();if(e.tagName==="INPUT"||e.tagName==="TEXTAREA"){let p=e;p.value=h(this.resolve(a)),p.addEventListener("input",d=>{let l=d.target.value;this.updateValue(a,l);}),this.bind({node:e,key:a,type:"model",context:this});}e.removeAttribute(r.name);}});let n=e.tagName.toLowerCase(),o=x.get(n),c={},i={};if(t!=="for"){let{props:r,events:a}=this.componentAttributes(e,this);c=r,i=a,this.expandStandardAttributes(e);}if(Object.keys(i).forEach(r=>{let a=i[r];e.addEventListener(r,p=>{typeof a=="function"&&a.apply(this.component,[p]);}),e.removeAttribute("@"+r);}),!t){if(o){this.mountComponent(e,o,this,c,i);return}[...e.childNodes].forEach(r=>this.render(r));}}handleTextNode(e){let t=e.textContent?.match(/\{\{(.*?)\}\}/g);t&&t.forEach(n=>{let o=n.replace(/[{}]/g,"").trim();this.bind({type:"interpolation",node:e,key:o,template:e.textContent,context:this});});}componentAttributes(e,t){let n={},o={},c=["import","interface","module","o-model","o-if","o-for"];return [...e.attributes].filter(i=>!c.includes(i.name)).forEach(i=>{let r=i.name;if(r.startsWith("@")){let d=t?.resolve(i.value,true);if(typeof d!="function")throw new Error("Event handler can only be function");r=r.substring(1),o[r]=d;return}let a=null,p=i.value;r.startsWith(":")&&(a=i.value,r=r.substring(1),p=t?.resolve(i.value),E(p)&&(p=p.value)),r=U(r),n[r]={name:r,value:p,expr:a};}),{props:n,events:o}}async mountComponent(e,t,n,o={},c={}){let i=document.createElement("div"),r=new s(this.app,null,null),a={};Object.keys(o).forEach(u=>{let f=o[u];f.expr&&this.bind({type:"prop",node:i,key:u,context:r,template:f.expr}),a[u]=f.value;});let p=await s.h(t,a,c);r.component=p,r.stack=[p.props],Object.keys(o).filter(u=>!o[u].expr).forEach(u=>i.setAttribute(u,o[u].value)),i.classList.add("o-component-host"),e.tagName.toLowerCase()!=="div"&&i.classList.add("c-"+e.tagName.toLowerCase()),p.willMount(),i.innerHTML=p.template.trim(),p.css&&(p.cssInstance=N(p.css));let d=Array.from(e.childNodes),l=i.querySelectorAll("o-slot");l&&l.forEach(u=>{let f=u.getAttribute("name");d.filter(y=>f?f&&y.nodeType===Node.ELEMENT_NODE&&y.getAttribute("slot")===f:y.nodeType!==Node.ELEMENT_NODE||!y.hasAttribute("slot")).forEach(y=>u.parentNode?.insertBefore(y,u));});let m=i;e.innerHTML="",e.appendChild(i),p.state.watch(()=>{r.updateBindings(),r.updateDirectives();}),p._hostElement=m,p.parent=n?.component??void 0,p.provide(s.PROVIDE_TOKEN,this),r.render(m),r.updateBindings(),r.updateDirectives(),this.mountedComponents.set(m,p),p.onMounted();}unmountComponent(e){let t=this.mountedComponents.get(e);t&&(S(t.cssInstance),t.willUnmount(),t._hostElement=null),e.querySelectorAll("*").forEach(n=>{this.unmountComponent(n);}),this.mountedComponents.delete(e);}static h(e,t,n){return G(e)?e().then(o=>b(o.default,t,n)):b(e,t,n)}};function W(s){return typeof s=="function"}var R=class s{constructor(e){this.root=e;s.currentApp=this;}static currentApp=null;providers=new Map;provide(e,t){if(this.providers.has(e)){console.warn(`[OUID] - Provider ${e} already exists`);return}this.providers.set(e,W(t)?{provide:t}:{value:t});}inject(e){return this.providers.get(e).value}use(e){return e.install(this),this}host;mount(e){let t=document.getElementById(e);if(!t)throw new Error("No selector found for "+e);this.host=t;let n=new g(this,null,null);n.mountComponent(this.host,this.root,null).then(()=>{n.updateBindings(),n.updateDirectives();});}};function de(s,e){R.currentApp.provide(s,e);}function j(s){return R.currentApp.inject(s)}exports.RouterComponent=class w extends O{routeStateHander=null;router;willMount(){}onMounted(){this.router=V(),console.log("Router mounted"),this.routeStateHander=this.router.bind(this),this.routeStateHander();}willUnmount(){console.log("Router will unmount"),this.router.unbind(this.routeStateHander);}};exports.RouterComponent=A([_({tag:"o-router",template:`
2
+ <div id="router-view"></div>
3
+ `})],exports.RouterComponent);var D="OROUTER_TOKEN",M="ACTIVE_ROUTE";function V(){return j(D)}function Ce(s){return new L(s)}function H(s,e){let t=new k__default.default(s.path).reverse(e);return t===false?"":t}var L=class{constructor(e){this.routes=e;}guards=[];install(e){e.provide(D,this);}resolve(e){let t=new k__default.default(e),n=e.split("?").reverse()[0].split("&").reduce((o,c)=>{let i=c.split("=");return o[i[0]]=decodeURIComponent(i[1]),o},{});for(let o of this.routes){let c=t.match(o.path);if(c)return {route:o,params:c,query:n}}return null}push(e){if(!e.path&&!e.name){console.warn("[OUID-Router]: no path or name provided to push");return}if(e.name){let t=this.routes.find(o=>o.name===e.name);if(!t){console.warn("[OUID-Router]: No matched route name found");return}let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}if(e.absolute&&window.history.pushState({},"",e.path),e.path){let t=this.routes.find(n=>n.path===e.path);if(t){let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}}}async beforeRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="before")){let o=await n.fn(e,t);if(o)return o}}async afterRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="after")){let o=await n.fn(e,t);if(o)return o}}bind(e){let t=async()=>{console.log("Handling routing",this);let n=window.location.pathname,o=this.resolve(n);if(console.log("Matched::",o),!o){console.warn(`[Router] No route found for: ${n}`);return}let c=await this.beforeRouteGoing({url:n,path:n,name:o.route.name},e.inject(M));if(c){typeof c=="object"&&"name"in c&&this.push({name:c.name,params:c.params});return}let i=e.inject(g.PROVIDE_TOKEN),r=i.hostElement.querySelector("#router-view");console.log("Outlet",r),r&&(r.innerHTML="",e.provide(M,{params:o.params,query:o.query}),await i.mountComponent(r,o.route.component,i),await this.afterRouteGoing({url:n,path:n,name:o.route.name},e.inject(M)));};return window.addEventListener("popstate",t.bind(this)),t}unbind(e){window.removeEventListener("popstate",e);}beforeEach(e){let t={fn:e,type:"before"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}afterEach(e){let t={fn:e,type:"after"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}};exports.ACTIVE_ROUTE_TOKEN=M;exports.App=R;exports.Component=_;exports.Emits=T;exports.OComponent=O;exports.ROUTER_INJECTION_TOKEN=D;exports.RenderContext=g;exports.Router=L;exports.State=C;exports.Stated=v;exports.createComponent=b;exports.createRouter=Ce;exports.inject=j;exports.isStated=E;exports.provide=de;exports.stated=B;exports.useRouter=V;//# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/emits.ts","../src/registry.ts","../src/state.ts","../src/component.ts","../src/style-injector.ts","../src/context.ts","../src/app.ts","../src/router/Router.ts"],"names":["Emits","events","event","args","handler","ComponentsRegistry","tag","compClass","key","componentsRegistry","Stated","value","isStated","ob","stated","target","state","proxify","seen","proxy","t","p","v","o","current","obj","State","data","oldValue","newValue","listener","path","now","Component","options","constructor","WithDecoration","createComponent","ctr","props","emits","OComponent","injectComponentStyles","css","styleEl","rejectComponentStyles","styleObj","toCamelCase","name","_","char","normaliseValue","toObjectWithFunctions","isLazyLoader","comp","RenderContext","_RenderContext","app","component","parentContext","frames","f","binding","directive","expr","strict","additionFrames","mergedFrame","frame","code","fn","error","b","k","d","show","e","oldChildren","newChildren","keyFn","val","idx","arr","last","keyedNode","node","localCtx","newCtx","keyed","classString","styleString","attr","controlled","placeholder","item","list","s","input","cc","child","matches","m","ignoredAttrs","a","hostNode","wrapper","handledProps","instance","children","slots","slot","rootEl","c","isProvideFunction","App","_App","root","token","plugin","selector","host","globalContext","provide","inject","RouterComponent","useRouter","__decorateClass","ROUTER_INJECTION_TOKEN","ACTIVE_ROUTE_TOKEN","createRouter","routes","Router","generatePath","route","params","RouteParser","parser","query","coll","tmps","r","match","to","from","guard","g","res","matched","guarded","context","outlet"],"mappings":"2JAAO,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,IAAMA,EAAN,KAA2C,CAC9C,WAAA,CAAoBC,CAAAA,CAAW,CAAX,I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CAAK,CAAC,EAC/C,CACF,CAEF","file":"index.js","sourcesContent":["export class Emits<O extends Record<string, any>> {\n constructor(private events: O) {\n }\n\n emit(event: keyof O, ...args: any) {\n const handler = this.events[event] as Function\n if(handler) {\n handler(...args)\n }\n }\n}","import { OComponentType } from \"./component\"\n\nclass ComponentsRegistry {\n private components: Map<string, OComponentType<any, any>> = new Map()\n register(tag: string, compClass: OComponentType<any, any>) {\n const key = tag.toLocaleLowerCase()\n if(this.components.has(key)) {\n console.warn(`[OUID] - ${key} component already registered`)\n return\n }\n console.debug('Registering new component: ' + tag, compClass)\n this.components.set(key, compClass)\n }\n unregister(tag: string) {\n const key = tag.toLocaleLowerCase()\n this.components.delete(key)\n }\n get(tag: string): OComponentType<any, any> {\n return this.components.get(tag.toLocaleLowerCase())\n }\n getAll() {\n return Array.from(this.components.entries())\n }\n}\nexport const componentsRegistry = new ComponentsRegistry()","export type StateWatcher<T> = <K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]) => void\nexport class Stated<T> {\n constructor(public value: T) { }\n}\nexport function isStated<T>(ob: any): ob is Stated<T> {\n return typeof ob === 'object' && !Array.isArray(ob) && 'value' in ob && ob instanceof Stated;\n}\nexport function stated<S, T>(target: T, state: State<S>): Stated<T> {\n const proxify = (target: any, seen: Map<any, any> = new Map()) => {\n if (seen.has(target)) {\n return seen[target]\n }\n const proxy = new Proxy(target, {\n set: (t, p, v) => {\n const o = t[p]\n if (typeof v === 'object') {\n t[p] = proxify(v)\n } else {\n t[p] = v\n }\n state.didChange(p as any, o, v)\n return true\n },\n get: (t, p) => {\n const v = Reflect.get(t, p)\n return v\n }\n })\n seen[target] = proxy\n for (let current = target; current; current = Object.getPrototypeOf(current)) {\n Object.keys(current).forEach(key => {\n const obj = target[key]\n if (typeof obj === 'object') {\n target[key] = proxify(obj, seen)\n }\n })\n }\n return proxy\n }\n if (typeof target === 'function') {\n throw new Error('Can\\'t create reactive element over a function')\n }\n if (typeof target !== 'object' && typeof target !== 'symbol') {\n return new Proxy(new Stated<T>(target), {\n set: (t, p, v) => {\n if (p !== 'value') throw new Error(`Undefined property ${String(p)} access`)\n const o = t[p]\n t[p] = v\n state.didChange(p as any, o, v)\n return true\n },\n get: (t, p) => {\n if (p !== 'value') throw new Error(`Undefined property ${String(p)} access`)\n return t[p]\n }\n })\n }\n\n return new Stated<T>(proxify(target))\n}\nexport class State<T extends Record<string, any>> {\n private THRESHOLD_TIME = 50\n private debounceTime = new Date().getTime()\n private state: T\n private listeners: StateWatcher<T>[] = []\n private timer = null\n constructor(data: T) {\n this.state = new Proxy(data, {\n set: (target, key: string, value: any) => {\n const oldValue = (target as any)[key];\n target[key as keyof T] = value\n this.didChange(key as keyof T, oldValue, value)\n return true\n },\n\n get: (target, key) => target[key as keyof T]\n }) as T\n }\n wrap<T>(obj: T): Stated<T> {\n return stated(obj, this)\n }\n has(key: keyof T): boolean {\n return key in this.state\n }\n setValue(key: keyof T, value: any) {\n this.state[key as keyof T] = value\n }\n getValue(key: keyof T): any {\n return this.state[key]\n }\n get value(): T {\n return this.state\n }\n\n private dispatchChanges<K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]): void {\n for (const listener of this.listeners) {\n listener(key, oldValue, newValue)\n }\n }\n\n didChange(path: keyof T, oldValue: any, newValue: any) {\n const now = Date.now()\n if (now - this.debounceTime <= this.THRESHOLD_TIME) {\n clearTimeout(this.timer);\n }\n\n this.debounceTime = now;\n\n this.timer = setTimeout(() => {\n this.dispatchChanges(path, oldValue, newValue);\n }, this.THRESHOLD_TIME);\n }\n\n watch(listener: StateWatcher<T>) {\n this.listeners.push(listener)\n return this.listeners.length - 1\n }\n\n unwatch(listener: StateWatcher<T> | number) {\n if (typeof listener === \"number\") {\n this.listeners.splice(listener, 1)\n return\n }\n this.listeners.splice(this.listeners.indexOf(listener), 1)\n }\n}","import { Emits } from \"./emits\";\nimport { componentsRegistry } from \"./registry\";\nimport { State } from \"./state\"\nexport type ComponentProps <K extends Record<string, any>> = K\n\nexport function Component(options: {template: string, tag: string, use?: OComponentType[], css?: string}) {\n return function <T extends { new(...args: any[]): {} }>(constructor: T) {\n const WithDecoration = class extends constructor {\n template = options.template;\n css = options.css\n };\n console.log('Construct', options.css)\n\n const compClass = WithDecoration as unknown as ComponentConstructor<any, any>;\n\n componentsRegistry.register(options.tag, compClass);\n return WithDecoration;\n\n };\n}\nexport interface Component<P extends Record<string, any>, O extends Record<string, any>> {\n // template: string\n state: State<any>\n readonly emits: Emits<O>\n readonly props: ComponentProps<P>\n onMounted(): void\n willMount(): void\n willUnmount(): void\n provide<T>(key: string, value: T): void\n inject<T>(key: string): T | undefined\n}\n\nexport interface ComponentConstructor<P extends Record<string, any>, O extends Record<string, any>> {\n new(props?: P, emits?: O): Component<P, O>\n}\nexport function createComponent< P extends Record<string, any>, O extends Record<string, any>>(ctr: ComponentConstructor<P, O>, props?: P, emits?: O): Component<P, O> {\n return new ctr(props, emits)\n}\nexport class OComponent<P extends Record<string, any> = {}, O extends Record<string, any> = {}> implements Component<P, O> {\n // template: string = \"\"\n state: State<any>\n private parent?: OComponent<any, any> = undefined\n readonly emits: Emits<O>\n readonly props: ComponentProps<P>\n private provides: Map<string, any> = new Map();\n\n constructor(props: P = {} as P, emits: O = {} as O) {\n this.state = new State(this)\n this.props = props\n this.emits = new Emits(emits)\n }\n onMounted(): void {\n }\n willMount(): void {\n \n }\n willUnmount(): void {\n \n }\n /** Provide a value for descendants */\n provide<T>(key: string, value: T) {\n this.provides.set(key, value);\n }\n\n /** Inject a value from nearest ancestor */\n inject<T>(key: string): T | undefined {\n let current: OComponent<any, any> | undefined = this;\n while (current) {\n if (current.provides.has(key)) {\n return current.provides.get(key);\n }\n current = current.parent;\n }\n return undefined;\n }\n}\nexport type LazyLoader<P extends Record<string, any>, O extends Record<string, any>> = () => Promise<{ default: ComponentConstructor<P, O> }>;\nexport type OComponentType<P extends Record<string, any> = {}, O extends Record<string, any> = {}> = \n| ComponentConstructor<P, O>\n| LazyLoader<P, O>","export function injectComponentStyles(css: string): HTMLStyleElement {\n const styleEl = document.createElement('style')\n console.log('css:', css)\n styleEl.innerHTML = css\n document.head.appendChild(styleEl)\n return styleEl\n}\n\n\nexport function rejectComponentStyles(styleObj: HTMLStyleElement | undefined): void {\n if (!styleObj) {\n return;\n }\n document.head.removeChild(styleObj)\n}\n","import { Component, ComponentConstructor, createComponent, OComponent, OComponentType } from \"./component\";\nimport { App } from \"./app\";\nimport { isStated } from \"./state\";\nimport { componentsRegistry } from \"./registry\";\nimport { injectComponentStyles, rejectComponentStyles } from \"./style-injector\";\n\nfunction toCamelCase(name: string): string {\n return name.replace(/-([a-z])/g, (_, char) => char.toUpperCase());\n}\n\nfunction normaliseValue<T>(value: T) {\n if (isStated(value)) {\n return value.value as T\n }\n return value\n}\nfunction toObjectWithFunctions(obj: any) {\n const props: Record<string, any> = {};\n\n for (let current = obj; current; current = Object.getPrototypeOf(current)) {\n Object.getOwnPropertyNames(current).forEach(key => {\n const v = obj[key]\n if (typeof v === \"function\" && key !== \"constructor\" && !key.startsWith('__') && !key.endsWith('__')) {\n if (!(key in props)) {\n props[key] = (v as Function).bind(obj)\n }\n } else if (key !== \"constructor\" && !key.startsWith('__') && !key.endsWith('__')) {\n if (!(key in props)) {\n props[key] = v\n }\n }\n });\n }\n\n return props\n}\n\nfunction isLazyLoader<P, O>(\n comp: OComponentType<P>\n): comp is () => Promise<{ default: ComponentConstructor<P, O> }> {\n return typeof comp === \"function\" && !(\"prototype\" in comp);\n}\n\nexport class RenderContext {\n static PROVIDE_TOKEN = \"RENDER_CONTEXT\"\n private bindings: Binding[] = []\n private directives: Directive[] = []\n private mountedComponents: WeakMap<any, OComponent> = new WeakMap()\n stack: Record<string, any>[] = []\n\n constructor(private app: App, public component: OComponent, private parentContext: RenderContext | null, ...frames: Record<string, any>[]) {\n for (const f of frames) {\n this.stack.push(f)\n }\n }\n get hostElement(): HTMLElement {\n return this.component['_hostElement']\n }\n bind(binding: Binding) {\n this.bindings.push(binding)\n }\n directive(directive: Directive) {\n this.directives.push(directive)\n }\n evaluateExpression(expr: string): boolean {\n return this.resolve(expr)\n }\n resolve(key: string, strict: boolean = true, ...additionFrames: Record<string, any>[]) {\n const state = this.component.state.value\n const props = toObjectWithFunctions(state)\n const mergedFrame = { ...props }\n for (const frame of [...this.stack.toReversed(), ...additionFrames]) {\n Object.assign(mergedFrame, frame)\n }\n try {\n const code = `${strict ? '\"use strict\";' : ''}return ${key};`\n const fn = new Function(...Object.keys(mergedFrame), code);\n fn.bind(this.component)\n const exe = fn.apply(this.component, Object.values(mergedFrame));\n return exe\n } catch (error) {\n console.log(this)\n console.error(error)\n }\n return undefined\n }\n /** \n * Handing (o-model) like (ngModel) update, we should support mutliple syntaxe like o-mode=\"value\" where value is defined directly on the component\n * o-model=\"data['key']\" where data is either defined on the component, of in the enclosing scope in case of for-loop for instance\n * */\n updateValue(key: string, value: any) {\n const firstPart = key.split(/[\\.\\[]/)[0]\n // check if the first part is part of the component\n if (firstPart in this.component) {\n // we put this before the key and make resolution (which indeed make a dynamic function creation and execution)\n this.resolve(`this.${key}=__o_model_value__`, true, { '__o_model_value__': value })\n } else {\n this.resolve(`${key}=__o_model_value__`, true, { '__o_model_value__': value })\n }\n this.component.state.didChange('', '', '')\n // this.component.state.setValue(key, value)\n }\n\n push(frame: Record<string, any>) {\n this.stack.unshift(frame)\n }\n pop() {\n this.stack.shift()\n }\n\n // --- Interpolation & two-way binding ---\n updateBindings() {\n this.bindings.forEach(b => this.updateBinding(b));\n }\n updateBinding(binding: Binding) {\n if (binding.type === \"model\") {\n (binding.node as any).value = normaliseValue<string>(binding.context.resolve(binding.key));\n } else if (binding.type === 'interpolation') {\n binding.node.textContent = binding.template?.replace(/\\{\\{(.*?)\\}\\}/g, (_, k) => {\n k = k.trim();\n return normaliseValue(binding.context.resolve(k))\n }) ?? '';\n } else if (binding.type === 'attribute') {\n const name = binding.key\n const v = normaliseValue(this.resolve(binding.template))\n if (name === 'class') {\n // expand class\n this.expandClass(binding.node, v)\n } else if (name === 'style') {\n this.expandStyle(binding.node, v)\n } else if (typeof v !== 'object' && typeof v !== 'function' && typeof v !== 'symbol' && typeof v !== 'undefined') {\n binding.node.setAttribute(name, v.toString())\n }\n } else if(binding.type === 'prop' && binding.context.component) {\n const value = normaliseValue<string>(this.resolve(binding.template))\n try {\n console.log({...binding.context.component})\n binding.context.component.props[binding.key] = value\n binding.context.updateBindings()\n binding.context.updateDirectives()\n } catch (error) {\n console.error(error)\n }\n }\n }\n // --- Directives ---\n updateDirectives() {\n for (let d of this.directives) {\n if (d.type === \"if\") {\n let show = false;\n try {\n // show = new Function(...Object.keys(this.state), `return (${d.expr});`)\n // (...Object.values(this.state));\n show = d.context.evaluateExpression(d.expr)\n if (isStated<boolean>(show)) {\n show = show.value\n }\n } catch (e) {\n console.error('Error:', e)\n }\n if (show) {\n if (d.active !== true) {\n d.active = true;\n d.placeholder.after(d.node);\n d.context.render(d.node);\n d.context.updateBindings();\n }\n // d.context.updateDirectives()\n } else if (!show) {\n if (d.active !== false) {\n this.unmountComponent(d.node)\n d.node.remove();\n d.active = false;\n }\n }\n }\n\n if (d.type === \"for\") {\n console.log('Start for directive', d)\n const oldChildren: Map<any, {node: ChildNode, ctx: RenderContext}> = d.children ?? new Map()\n const newChildren: Map<any, {node: ChildNode, ctx: RenderContext}> = new Map()\n const keyFn = (val, idx) => d.key ? normaliseValue<any>(d.context.resolve(d.key, true, { [d.item!]: val })) : idx\n\n let arr = normaliseValue<any[]>(d.context.resolve(d.list!)) || [];\n console.log('For-directive', arr)\n let last: ChildNode = d.placeholder\n arr.forEach(async (val, idx) => {\n const key = keyFn(val, idx)\n const keyedNode = oldChildren.get(key)\n let node = keyedNode?.node\n let localCtx = { [d.item!]: val };\n const newCtx = keyedNode?.ctx ?? new RenderContext(this.app, this.component, null)\n newCtx.stack = [localCtx, ...d.context.stack]\n if (!node) {\n // create new node\n node = d.node.cloneNode(true) as ChildNode;\n newCtx.render(node);\n last.after(node);\n newCtx.updateBindings();\n newCtx.updateDirectives();\n } else {\n newCtx.updateBindings();\n newCtx.updateDirectives();\n }\n last = node\n newChildren.set(key, {node, ctx: newCtx})\n });\n // remove old nodes not in new list\n oldChildren.forEach((keyed, key) => {\n if (!newChildren.has(key)) {\n this.unmountComponent(keyed.node as Element);\n keyed.node.remove();\n }\n });\n d.children = newChildren\n }\n }\n }\n\n private render(node: Node) {\n switch (node.nodeType) {\n case Node.TEXT_NODE:\n this.handleTextNode(node as HTMLElement)\n break\n case Node.ELEMENT_NODE:\n this.handleElementNode(node as HTMLElement)\n break\n default:\n console.warn(\"Unknown node\", node)\n }\n }\n private expandClass(node: HTMLElement, value: any) {\n let classString = value\n if (typeof value === 'object') {\n if (Array.isArray(value)) {\n classString = value.join(' ')\n } else {\n classString = Object.keys(value).filter(e => value[e]).join(' ')\n }\n }\n node.setAttribute('class', classString)\n }\n private expandStyle(node: HTMLElement, value: any) {\n let styleString = value\n if (typeof value === 'object' && !Array.isArray(value)) {\n styleString = Object.keys(value).map(e => `${e}: ${value[e]}`).join(';')\n }\n node.setAttribute('style', styleString)\n }\n private expandStandardAttributes(node: HTMLElement) {\n\n [...node.attributes].filter(attr => attr.name.startsWith(':')).filter(attr => [':id', ':style', ':class', ':placeholder'].includes(attr.name)).forEach(attr => {\n const key = attr.name.substring(1)\n this.bind({\n type: 'attribute',\n node,\n key,\n context: this,\n template: attr.value.trim()\n })\n node.removeAttribute(attr.name)\n })\n }\n handleElementNode(node: HTMLElement) {\n // expand style and classes\n\n let controlled: 'for' | 'if' | null = null\n // *if directive\n if (node.hasAttribute(\"o-if\")) {\n const expr = node.getAttribute(\"o-if\")!;\n const placeholder = document.createComment(\"o-if:\" + expr);\n node.parentNode?.insertBefore(placeholder, node);\n node.removeAttribute(\"o-if\");\n this.directive({\n type: \"if\",\n expr,\n node,\n placeholder,\n context: this,\n active: undefined\n });\n controlled = 'if'\n }\n\n // *for directive\n if (node.hasAttribute(\"o-for\")) {\n if (controlled === 'if') {\n throw new Error('Can\\'t have o-if and o-for on the same component')\n }\n const expr = node.getAttribute(\"o-for\")!;\n const [item, list] = expr.split(\" of \").map(s => s.trim());\n const placeholder = document.createComment(\"for:\" + expr);\n const key = node.getAttribute(':key')\n node.parentNode?.insertBefore(placeholder, node);\n node.removeAttribute(\"o-for\");\n node.removeAttribute(':key')\n node.remove();\n this.directive({\n type: \"for\",\n item,\n list,\n node,\n placeholder,\n context: this,\n key,\n });\n controlled = 'for'\n }\n if (controlled !== 'for') {\n // Two-way binding [(model)]\n [...node.attributes].forEach(attr => {\n if (attr.name === 'o-model') {\n const key = attr.value.trim();\n if (node.tagName === \"INPUT\" || node.tagName === \"TEXTAREA\") {\n const input = node as HTMLInputElement | HTMLTextAreaElement\n input.value = normaliseValue(this.resolve(key,));\n input.addEventListener(\"input\", (e) => {\n // this.state[key] = (e.target as any).value;\n const value = (e.target as any).value\n this.updateValue(key, value)\n\n });\n this.bind({ node, key, type: \"model\", context: this });\n }\n node.removeAttribute(attr.name);\n }\n });\n }\n\n\n const tag = node.tagName.toLowerCase();\n const cc = componentsRegistry.get(tag)\n let props = {} as any, events = {} as any\n if (controlled !== 'for') {\n const { props: p, events: e } = this.componentAttributes(node, this)\n props = p\n events = e\n this.expandStandardAttributes(node)\n }\n // Event binding @(event)=\"fn()\"\n Object.keys(events).forEach(k => {\n const handler = events[k]\n node.addEventListener(k, e => {\n if (typeof handler === \"function\") (handler as Function).apply(this.component, [e]);\n });\n node.removeAttribute('@' + k);\n });\n if (controlled) {\n return\n }\n\n if (cc) {\n this.mountComponent(node, cc, this, props, events);\n return; // stop scanning original node\n }\n [...node.childNodes].forEach(child => this.render(child as HTMLElement));\n }\n handleTextNode(node: HTMLElement) {\n const matches = node.textContent?.match(/\\{\\{(.*?)\\}\\}/g);\n if (matches) {\n matches.forEach(m => {\n const key = m.replace(/[{}]/g, \"\").trim();\n this.bind({ type: 'interpolation', node, key, template: node.textContent, context: this });\n });\n }\n }\n private componentAttributes(node: HTMLElement, parentContext: RenderContext | null) {\n const props: Record<string, { name: string, expr?: string, value: any }> = {};\n const events: any = {};\n const ignoredAttrs = ['import', 'interface', 'module', 'o-model', 'o-if', 'o-for'];\n [...node.attributes].filter(a => !ignoredAttrs.includes(a.name)).forEach(attr => {\n let name = attr.name\n if (name.startsWith('@')) {\n // attach an event\n const handler = parentContext?.resolve(attr.value, true)\n if (typeof handler !== 'function') {\n throw new Error('Event handler can only be function')\n }\n name = name.substring(1)\n events[name] = handler\n return\n }\n let expr: string | null = null\n let p: any = attr.value\n if (name.startsWith(':')) {\n expr = attr.value\n name = name.substring(1)\n p = parentContext?.resolve(attr.value)\n if (isStated(p)) {\n p = p.value\n } // ????\n }\n name = toCamelCase(name)\n props[name] = {\n name,\n value: p,\n expr\n };\n });\n return { props, events }\n }\n async mountComponent<T, O>(hostNode: HTMLElement, component: OComponentType<T, O>, parentContext: RenderContext, props: Record<string, { name: string, value: any, expr?: string }> = {}, emits: O = {} as O) {\n // Props from attributes\n // const { props, events } = this.componentAttributes(hostNode, parentContext);\n const wrapper = document.createElement('div');\n const newCtx = new RenderContext(this.app, null, null)\n const handledProps = {} as T\n Object.keys(props).forEach(k => {\n const p = props[k]\n if (p.expr) {\n // create a binding\n this.bind({\n type: 'prop',\n node: wrapper,\n key: k,\n context: newCtx,\n template: p.expr\n })\n }\n handledProps[k] = p.value\n })\n\n const instance = await RenderContext.h(component, handledProps, emits);\n newCtx.component = instance\n newCtx.stack = [instance.props]\n Object.keys(props).filter(e => !props[e].expr).forEach(attr => wrapper.setAttribute(attr, props[attr].value))\n wrapper.classList.add('o-component-host')\n if (hostNode.tagName.toLowerCase() !== 'div') {\n wrapper.classList.add('c-' + hostNode.tagName.toLowerCase())\n }\n instance.willMount()\n wrapper.innerHTML = instance['template'].trim();\n if (instance['css']) {\n instance['cssInstance'] = injectComponentStyles(instance['css'])\n }\n // append css if any \n const children = Array.from(hostNode.childNodes)\n const slots = wrapper.querySelectorAll('o-slot')\n if (slots) {\n // there are some slot, so we make injections\n slots.forEach(slot => {\n const name = slot.getAttribute('name')\n children.filter(e => {\n if (!name) {\n return e.nodeType !== Node.ELEMENT_NODE || !(e as Element).hasAttribute('slot')\n }\n return name && e.nodeType === Node.ELEMENT_NODE && (e as Element).getAttribute('slot') === name\n }).forEach(node => slot.parentNode?.insertBefore(node, slot))\n })\n }\n const rootEl = wrapper;\n // this.unmountComponent(hostNode)\n hostNode.innerHTML = \"\"\n hostNode.appendChild(wrapper)\n \n instance.state.watch(() => {\n newCtx.updateBindings();\n newCtx.updateDirectives();\n })\n instance['_hostElement'] = rootEl\n instance['parent'] = parentContext?.component ?? undefined\n instance.provide(RenderContext.PROVIDE_TOKEN, this)\n // attach rootEl to this component\n newCtx.render(rootEl);\n newCtx.updateBindings();\n newCtx.updateDirectives();\n this.mountedComponents.set(rootEl, instance)\n instance.onMounted()\n }\n unmountComponent(node: Element) {\n const comp = this.mountedComponents.get(node)\n if (comp) {\n // emit will unmount\n rejectComponentStyles(comp['cssInstance'])\n comp.willUnmount()\n comp['_hostElement'] = null\n }\n node.querySelectorAll('*').forEach(child => {\n this.unmountComponent(child)\n })\n this.mountedComponents.delete(node)\n }\n static h<P, O>(component: ComponentConstructor<P, O>, props: P, emits?: O): OComponent<P>;\n static async h<P, O>(component: OComponentType<P>, props: P, emits?: O): Promise<OComponent<P>>\n\n\n static h<P, O>(component: OComponentType<P, O>, props: P, emits?: O): Component<P, O> | Promise<Component<P, O>> {\n if (isLazyLoader(component)) {\n return component().then((c) => createComponent(c.default, props, emits))\n } else {\n return createComponent(component, props, emits);\n }\n }\n}\nexport type Binding = { type: 'model' | 'interpolation' | 'attribute' | 'prop', node: HTMLElement, key: string, template?: string | null, context: RenderContext }\nexport type Directive = { type: 'if' | 'for', node: HTMLElement, expr?: string, placeholder: Comment, context: RenderContext, active?: boolean, list?: string, item?: string, children?: Map<any, {node: ChildNode, ctx: RenderContext}>, key?: string }\n","import { ComponentConstructor, createComponent, OComponent, OComponentType } from \"./component\";\nimport { RenderContext } from \"./context\";\n\n\n\ntype ProvideFunction<T> = () => T\nexport type Provider<T = any> = {\n value?: T,\n provide?: ProvideFunction<T>\n}\nfunction isProvideFunction<T>(fn: T | ProvideFunction<T>): fn is ProvideFunction<T> {\n return typeof fn === 'function'\n}\nexport interface Plugin {\n install(app: App): void\n}\n/** Injection token key */\nexport type InjectionKey = string\n/** Providers type */\nexport type Providers = Map<InjectionKey, Provider>\n/**\n * OUIDesigner App\n */\nexport class App {\n static currentApp: App | null = null\n private providers: Providers = new Map()\n /**\n * Provide a value through a key to all the app globally\n * @param token the registration key\n * @param value the provider value\n */\n provide<T>(token: InjectionKey, value: T | (() => T)): void {\n if (this.providers.has(token)) {\n console.warn(`[OUID] - Provider ${token} already exists`)\n return\n }\n this.providers.set(token, isProvideFunction(value) ? { provide: value } : { value: value })\n }\n /**\n * Get globally a provider through a given key\n * @param token the key to look up globally\n * @returns a provider value\n */\n inject<T>(token: InjectionKey): T {\n return this.providers.get(token).value as T\n }\n /**\n * Register a plugin to be used by this app\n * @param plugin the plugin to register\n * @returns `this` App instance\n */\n use(plugin: Plugin) {\n plugin.install(this)\n return this\n }\n private host: HTMLElement\n constructor(private root: ComponentConstructor<any, any>) {\n App.currentApp = this\n }\n /**\n * Mount the App in a host element\n * @param selector the host element where the app's root component should be mounted\n */\n mount(selector: string) {\n const host = document.getElementById(selector)\n if (!host) throw new Error(\"No selector found for \" + selector)\n this.host = host\n\n const globalContext = new RenderContext(this, null, null)\n globalContext.mountComponent(this.host, this.root, null).then(() => {\n globalContext.updateBindings()\n globalContext.updateDirectives()\n })\n }\n}\n\n/**\n * Provide a value through a key to all the app globally\n * @param token the registration key\n * @param value the provider value\n */\nexport function provide<T>(token: InjectionKey, value: T | (() => T)): void {\n App.currentApp.provide(token, value)\n}\n/**\n * Get globally a provider through a given key\n * @param token the key to look up globally\n * @returns a provider value\n */\nexport function inject<T>(token: InjectionKey): T {\n return App.currentApp.inject(token)\n}","import RouteParser from 'route-parser'\nimport { App, inject, Plugin } from '../app'\nimport { Component, OComponent, OComponentType } from '../component'\nimport { RenderContext } from '../context'\n/**\n * Component responsible for display routes\n * Usage: <o-router></o-router>\n */\n@Component({\n tag: 'o-router',\n template: `\n <div id=\"router-view\"></div>\n `\n})\nexport class RouterComponent extends OComponent {\n private routeStateHander: (() => void) | null = null\n private router: Router\n willMount(): void {\n }\n onMounted(): void {\n this.router = useRouter()\n console.log('Router mounted')\n this.routeStateHander = this.router.bind(this)\n this.routeStateHander();\n }\n willUnmount(): void {\n console.log('Router will unmount')\n this.router.unbind(this.routeStateHander);\n }\n}\nexport const ROUTER_INJECTION_TOKEN = \"OROUTER_TOKEN\"\nexport const ACTIVE_ROUTE_TOKEN = \"ACTIVE_ROUTE\"\nexport interface Route {\n path?: string\n name: string\n component?: OComponentType,\n redirectTo?: string\n}\n\nexport function useRouter(): Router {\n return inject<Router>(ROUTER_INJECTION_TOKEN)\n}\nexport function createRouter(routes: Routes): Router {\n return new Router(routes)\n}\nexport type Routes = Array<Route>\nfunction generatePath(route: Route, params: Record<string, string>): string {\n let path = new RouteParser(route.path).reverse(params)\n if (path === false) return \"\"\n return path\n}\ntype MatchedRoute = { route: Route, params: Record<string, any>, query: Record<string, string> }\nexport type Promised<T> = T | Promise<T>\nexport type RouteLocationNamed = {name: string, params?: Record<string, any>}\nexport type RouteGuardReturn = void | boolean | RouteLocationNamed\nexport type RouteGaurdFunction = (to: {url: string, path: string, name: string }, from?: {query: Record<string, string>, params: Record<string, string>}) => Promised<RouteGuardReturn>\nexport interface RouteGuard {\n type: 'before' | 'after',\n fn: RouteGaurdFunction\n}\nexport class Router implements Plugin {\n private guards: Array<RouteGuard> = []\n constructor(public routes: Routes) {\n }\n install(app: App) {\n app.provide(ROUTER_INJECTION_TOKEN, this)\n }\n resolve(path: string): MatchedRoute {\n const parser = new RouteParser(path)\n const query: Record<string, string> = path.split('?').reverse()[0].split('&').reduce((coll, value) => {\n const tmps = value.split('=')\n coll[tmps[0]] = decodeURIComponent(tmps[1])\n return coll\n }, {})\n for (const r of this.routes) {\n const match = parser.match(r.path)\n if (match) {\n return {\n route: r,\n params: match,\n query\n }\n }\n }\n return null\n }\n push(options: { name?: string, path?: string, params?: Record<string, string>, absolute?: boolean }): void {\n if (!options.path && !options.name) {\n console.warn('[OUID-Router]: no path or name provided to push')\n return\n }\n\n if (options.name) {\n const route = this.routes.find(r => r.name === options.name)\n if (!route) {\n console.warn('[OUID-Router]: No matched route name found')\n return\n }\n const path = generatePath(route, options.params)\n window.history.pushState({}, \"\", path);\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n return\n }\n if (options.absolute) {\n window.history.pushState({}, \"\", options.path);\n }\n if (options.path) {\n // first try to match direct path\n const route = this.routes.find(r => r.path === options.path)\n if (route) {\n const path = generatePath(route, options.params)\n window.history.pushState({}, \"\", path);\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n return\n }\n }\n\n }\n\n private async beforeRouteGoing(to: {url: string, path: string, name: string }, from: { params: Record<string, any>, query: Record<string, any> }): Promise<RouteGuardReturn> {\n for (const guard of this.guards.filter(g => g.type === 'before')) {\n const res = await guard.fn(to, from)\n if (res) {\n return res\n }\n }\n return\n }\n private async afterRouteGoing(to: {url: string, path: string, name: string }, from: { params: Record<string, any>, query: Record<string, any> }): Promise<RouteGuardReturn> {\n for (const guard of this.guards.filter(g => g.type === 'after')) {\n const res = await guard.fn(to, from)\n if (res) {\n return res\n }\n }\n return\n }\n\n bind(component: RouterComponent): (() => void) {\n const handler = async () => {\n console.log('Handling routing', this)\n const path = window.location.pathname;\n const matched = this.resolve(path);\n console.log('Matched::', matched)\n if (!matched) {\n console.warn(`[Router] No route found for: ${path}`);\n return;\n }\n const guarded = await this.beforeRouteGoing({url: path, path, name: matched.route.name}, component.inject(ACTIVE_ROUTE_TOKEN))\n if (guarded) {\n if(typeof guarded === 'object' && 'name' in guarded) {\n // redirection\n this.push({name: guarded.name, params: guarded.params})\n }\n return;\n }\n const context = component.inject<RenderContext>(RenderContext.PROVIDE_TOKEN)\n const outlet = context.hostElement.querySelector(\"#router-view\") as HTMLElement | null;\n console.log('Outlet', outlet)\n if (!outlet) return;\n outlet.innerHTML = \"\"; // clear previous\n component.provide(ACTIVE_ROUTE_TOKEN, {\n params: matched.params,\n query: matched.query\n })\n await context.mountComponent(outlet, matched.route.component, context)\n await this.afterRouteGoing({url: path, path, name: matched.route.name}, component.inject(ACTIVE_ROUTE_TOKEN))\n\n }\n window.addEventListener('popstate', handler.bind(this))\n return handler\n }\n\n unbind(handler: () => void) {\n window.removeEventListener('popstate', handler)\n }\n\n beforeEach(fn: RouteGaurdFunction): (() => void) {\n const guard = {\n fn,\n type: 'before'\n } as RouteGuard\n this.guards.push(guard)\n return () => {\n this.guards.splice(this.guards.indexOf(guard))\n }\n }\n afterEach(fn: RouteGaurdFunction): (() => void) {\n const guard = {\n fn,\n type: 'after'\n } as RouteGuard\n this.guards.push(guard)\n return () => {\n this.guards.splice(this.guards.indexOf(guard))\n }\n }\n\n}"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import k from'route-parser';var A=(s,e,t,n)=>{for(var o=e,c=s.length-1,i;c>=0;c--)(i=s[c])&&(o=(i(o))||o);return o};var T=class{constructor(e){this.events=e;}emit(e,...t){let n=this.events[e];n&&n(...t);}};var P=class{components=new Map;register(e,t){let n=e.toLocaleLowerCase();if(this.components.has(n)){console.warn(`[OUID] - ${n} component already registered`);return}console.debug("Registering new component: "+e,t),this.components.set(n,t);}unregister(e){let t=e.toLocaleLowerCase();this.components.delete(t);}get(e){return this.components.get(e.toLocaleLowerCase())}getAll(){return Array.from(this.components.entries())}},x=new P;var v=class{constructor(e){this.value=e;}};function E(s){return typeof s=="object"&&!Array.isArray(s)&&"value"in s&&s instanceof v}function B(s,e){let t=(n,o=new Map)=>{if(o.has(n))return o[n];let c=new Proxy(n,{set:(i,r,a)=>{let p=i[r];return typeof a=="object"?i[r]=t(a):i[r]=a,e.didChange(r,p,a),true},get:(i,r)=>Reflect.get(i,r)});o[n]=c;for(let i=n;i;i=Object.getPrototypeOf(i))Object.keys(i).forEach(r=>{let a=n[r];typeof a=="object"&&(n[r]=t(a,o));});return c};if(typeof s=="function")throw new Error("Can't create reactive element over a function");return typeof s!="object"&&typeof s!="symbol"?new Proxy(new v(s),{set:(n,o,c)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);let i=n[o];return n[o]=c,e.didChange(o,i,c),true},get:(n,o)=>{if(o!=="value")throw new Error(`Undefined property ${String(o)} access`);return n[o]}}):new v(t(s))}var C=class{THRESHOLD_TIME=50;debounceTime=new Date().getTime();state;listeners=[];timer=null;constructor(e){this.state=new Proxy(e,{set:(t,n,o)=>{let c=t[n];return t[n]=o,this.didChange(n,c,o),true},get:(t,n)=>t[n]});}wrap(e){return B(e,this)}has(e){return e in this.state}setValue(e,t){this.state[e]=t;}getValue(e){return this.state[e]}get value(){return this.state}dispatchChanges(e,t,n){for(let o of this.listeners)o(e,t,n);}didChange(e,t,n){let o=Date.now();o-this.debounceTime<=this.THRESHOLD_TIME&&clearTimeout(this.timer),this.debounceTime=o,this.timer=setTimeout(()=>{this.dispatchChanges(e,t,n);},this.THRESHOLD_TIME);}watch(e){return this.listeners.push(e),this.listeners.length-1}unwatch(e){if(typeof e=="number"){this.listeners.splice(e,1);return}this.listeners.splice(this.listeners.indexOf(e),1);}};function _(s){return function(e){let t=class extends e{template=s.template;css=s.css};console.log("Construct",s.css);let n=t;return x.register(s.tag,n),t}}function b(s,e,t){return new s(e,t)}var O=class{state;parent=void 0;emits;props;provides=new Map;constructor(e={},t={}){this.state=new C(this),this.props=e,this.emits=new T(t);}onMounted(){}willMount(){}willUnmount(){}provide(e,t){this.provides.set(e,t);}inject(e){let t=this;for(;t;){if(t.provides.has(e))return t.provides.get(e);t=t.parent;}}};function N(s){let e=document.createElement("style");return console.log("css:",s),e.innerHTML=s,document.head.appendChild(e),e}function S(s){s&&document.head.removeChild(s);}function U(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function h(s){return E(s)?s.value:s}function F(s){let e={};for(let t=s;t;t=Object.getPrototypeOf(t))Object.getOwnPropertyNames(t).forEach(n=>{let o=s[n];typeof o=="function"&&n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")?n in e||(e[n]=o.bind(s)):n!=="constructor"&&!n.startsWith("__")&&!n.endsWith("__")&&(n in e||(e[n]=o));});return e}function G(s){return typeof s=="function"&&!("prototype"in s)}var g=class s{constructor(e,t,n,...o){this.app=e;this.component=t;this.parentContext=n;for(let c of o)this.stack.push(c);}static PROVIDE_TOKEN="RENDER_CONTEXT";bindings=[];directives=[];mountedComponents=new WeakMap;stack=[];get hostElement(){return this.component._hostElement}bind(e){this.bindings.push(e);}directive(e){this.directives.push(e);}evaluateExpression(e){return this.resolve(e)}resolve(e,t=true,...n){let o=this.component.state.value,i={...F(o)};for(let r of [...this.stack.toReversed(),...n])Object.assign(i,r);try{let r=`${t?'"use strict";':""}return ${e};`,a=new Function(...Object.keys(i),r);return a.bind(this.component),a.apply(this.component,Object.values(i))}catch(r){console.log(this),console.error(r);}}updateValue(e,t){e.split(/[\.\[]/)[0]in this.component?this.resolve(`this.${e}=__o_model_value__`,true,{__o_model_value__:t}):this.resolve(`${e}=__o_model_value__`,true,{__o_model_value__:t}),this.component.state.didChange("","","");}push(e){this.stack.unshift(e);}pop(){this.stack.shift();}updateBindings(){this.bindings.forEach(e=>this.updateBinding(e));}updateBinding(e){if(e.type==="model")e.node.value=h(e.context.resolve(e.key));else if(e.type==="interpolation")e.node.textContent=e.template?.replace(/\{\{(.*?)\}\}/g,(t,n)=>(n=n.trim(),h(e.context.resolve(n))))??"";else if(e.type==="attribute"){let t=e.key,n=h(this.resolve(e.template));t==="class"?this.expandClass(e.node,n):t==="style"?this.expandStyle(e.node,n):typeof n!="object"&&typeof n!="function"&&typeof n!="symbol"&&typeof n<"u"&&e.node.setAttribute(t,n.toString());}else if(e.type==="prop"&&e.context.component){let t=h(this.resolve(e.template));try{console.log({...e.context.component}),e.context.component.props[e.key]=t,e.context.updateBindings(),e.context.updateDirectives();}catch(n){console.error(n);}}}updateDirectives(){for(let e of this.directives){if(e.type==="if"){let t=false;try{t=e.context.evaluateExpression(e.expr),E(t)&&(t=t.value);}catch(n){console.error("Error:",n);}t?e.active!==true&&(e.active=true,e.placeholder.after(e.node),e.context.render(e.node),e.context.updateBindings()):t||e.active!==false&&(this.unmountComponent(e.node),e.node.remove(),e.active=false);}if(e.type==="for"){console.log("Start for directive",e);let t=e.children??new Map,n=new Map,o=(r,a)=>e.key?h(e.context.resolve(e.key,true,{[e.item]:r})):a,c=h(e.context.resolve(e.list))||[];console.log("For-directive",c);let i=e.placeholder;c.forEach(async(r,a)=>{let p=o(r,a),d=t.get(p),l=d?.node,m={[e.item]:r},u=d?.ctx??new s(this.app,this.component,null);u.stack=[m,...e.context.stack],l?(u.updateBindings(),u.updateDirectives()):(l=e.node.cloneNode(true),u.render(l),i.after(l),u.updateBindings(),u.updateDirectives()),i=l,n.set(p,{node:l,ctx:u});}),t.forEach((r,a)=>{n.has(a)||(this.unmountComponent(r.node),r.node.remove());}),e.children=n;}}}render(e){switch(e.nodeType){case Node.TEXT_NODE:this.handleTextNode(e);break;case Node.ELEMENT_NODE:this.handleElementNode(e);break;default:console.warn("Unknown node",e);}}expandClass(e,t){let n=t;typeof t=="object"&&(Array.isArray(t)?n=t.join(" "):n=Object.keys(t).filter(o=>t[o]).join(" ")),e.setAttribute("class",n);}expandStyle(e,t){let n=t;typeof t=="object"&&!Array.isArray(t)&&(n=Object.keys(t).map(o=>`${o}: ${t[o]}`).join(";")),e.setAttribute("style",n);}expandStandardAttributes(e){[...e.attributes].filter(t=>t.name.startsWith(":")).filter(t=>[":id",":style",":class",":placeholder"].includes(t.name)).forEach(t=>{let n=t.name.substring(1);this.bind({type:"attribute",node:e,key:n,context:this,template:t.value.trim()}),e.removeAttribute(t.name);});}handleElementNode(e){let t=null;if(e.hasAttribute("o-if")){let r=e.getAttribute("o-if"),a=document.createComment("o-if:"+r);e.parentNode?.insertBefore(a,e),e.removeAttribute("o-if"),this.directive({type:"if",expr:r,node:e,placeholder:a,context:this,active:void 0}),t="if";}if(e.hasAttribute("o-for")){if(t==="if")throw new Error("Can't have o-if and o-for on the same component");let r=e.getAttribute("o-for"),[a,p]=r.split(" of ").map(m=>m.trim()),d=document.createComment("for:"+r),l=e.getAttribute(":key");e.parentNode?.insertBefore(d,e),e.removeAttribute("o-for"),e.removeAttribute(":key"),e.remove(),this.directive({type:"for",item:a,list:p,node:e,placeholder:d,context:this,key:l}),t="for";}t!=="for"&&[...e.attributes].forEach(r=>{if(r.name==="o-model"){let a=r.value.trim();if(e.tagName==="INPUT"||e.tagName==="TEXTAREA"){let p=e;p.value=h(this.resolve(a)),p.addEventListener("input",d=>{let l=d.target.value;this.updateValue(a,l);}),this.bind({node:e,key:a,type:"model",context:this});}e.removeAttribute(r.name);}});let n=e.tagName.toLowerCase(),o=x.get(n),c={},i={};if(t!=="for"){let{props:r,events:a}=this.componentAttributes(e,this);c=r,i=a,this.expandStandardAttributes(e);}if(Object.keys(i).forEach(r=>{let a=i[r];e.addEventListener(r,p=>{typeof a=="function"&&a.apply(this.component,[p]);}),e.removeAttribute("@"+r);}),!t){if(o){this.mountComponent(e,o,this,c,i);return}[...e.childNodes].forEach(r=>this.render(r));}}handleTextNode(e){let t=e.textContent?.match(/\{\{(.*?)\}\}/g);t&&t.forEach(n=>{let o=n.replace(/[{}]/g,"").trim();this.bind({type:"interpolation",node:e,key:o,template:e.textContent,context:this});});}componentAttributes(e,t){let n={},o={},c=["import","interface","module","o-model","o-if","o-for"];return [...e.attributes].filter(i=>!c.includes(i.name)).forEach(i=>{let r=i.name;if(r.startsWith("@")){let d=t?.resolve(i.value,true);if(typeof d!="function")throw new Error("Event handler can only be function");r=r.substring(1),o[r]=d;return}let a=null,p=i.value;r.startsWith(":")&&(a=i.value,r=r.substring(1),p=t?.resolve(i.value),E(p)&&(p=p.value)),r=U(r),n[r]={name:r,value:p,expr:a};}),{props:n,events:o}}async mountComponent(e,t,n,o={},c={}){let i=document.createElement("div"),r=new s(this.app,null,null),a={};Object.keys(o).forEach(u=>{let f=o[u];f.expr&&this.bind({type:"prop",node:i,key:u,context:r,template:f.expr}),a[u]=f.value;});let p=await s.h(t,a,c);r.component=p,r.stack=[p.props],Object.keys(o).filter(u=>!o[u].expr).forEach(u=>i.setAttribute(u,o[u].value)),i.classList.add("o-component-host"),e.tagName.toLowerCase()!=="div"&&i.classList.add("c-"+e.tagName.toLowerCase()),p.willMount(),i.innerHTML=p.template.trim(),p.css&&(p.cssInstance=N(p.css));let d=Array.from(e.childNodes),l=i.querySelectorAll("o-slot");l&&l.forEach(u=>{let f=u.getAttribute("name");d.filter(y=>f?f&&y.nodeType===Node.ELEMENT_NODE&&y.getAttribute("slot")===f:y.nodeType!==Node.ELEMENT_NODE||!y.hasAttribute("slot")).forEach(y=>u.parentNode?.insertBefore(y,u));});let m=i;e.innerHTML="",e.appendChild(i),p.state.watch(()=>{r.updateBindings(),r.updateDirectives();}),p._hostElement=m,p.parent=n?.component??void 0,p.provide(s.PROVIDE_TOKEN,this),r.render(m),r.updateBindings(),r.updateDirectives(),this.mountedComponents.set(m,p),p.onMounted();}unmountComponent(e){let t=this.mountedComponents.get(e);t&&(S(t.cssInstance),t.willUnmount(),t._hostElement=null),e.querySelectorAll("*").forEach(n=>{this.unmountComponent(n);}),this.mountedComponents.delete(e);}static h(e,t,n){return G(e)?e().then(o=>b(o.default,t,n)):b(e,t,n)}};function W(s){return typeof s=="function"}var R=class s{constructor(e){this.root=e;s.currentApp=this;}static currentApp=null;providers=new Map;provide(e,t){if(this.providers.has(e)){console.warn(`[OUID] - Provider ${e} already exists`);return}this.providers.set(e,W(t)?{provide:t}:{value:t});}inject(e){return this.providers.get(e).value}use(e){return e.install(this),this}host;mount(e){let t=document.getElementById(e);if(!t)throw new Error("No selector found for "+e);this.host=t;let n=new g(this,null,null);n.mountComponent(this.host,this.root,null).then(()=>{n.updateBindings(),n.updateDirectives();});}};function de(s,e){R.currentApp.provide(s,e);}function j(s){return R.currentApp.inject(s)}var w=class extends O{routeStateHander=null;router;willMount(){}onMounted(){this.router=V(),console.log("Router mounted"),this.routeStateHander=this.router.bind(this),this.routeStateHander();}willUnmount(){console.log("Router will unmount"),this.router.unbind(this.routeStateHander);}};w=A([_({tag:"o-router",template:`
2
+ <div id="router-view"></div>
3
+ `})],w);var D="OROUTER_TOKEN",M="ACTIVE_ROUTE";function V(){return j(D)}function Ce(s){return new L(s)}function H(s,e){let t=new k(s.path).reverse(e);return t===false?"":t}var L=class{constructor(e){this.routes=e;}guards=[];install(e){e.provide(D,this);}resolve(e){let t=new k(e),n=e.split("?").reverse()[0].split("&").reduce((o,c)=>{let i=c.split("=");return o[i[0]]=decodeURIComponent(i[1]),o},{});for(let o of this.routes){let c=t.match(o.path);if(c)return {route:o,params:c,query:n}}return null}push(e){if(!e.path&&!e.name){console.warn("[OUID-Router]: no path or name provided to push");return}if(e.name){let t=this.routes.find(o=>o.name===e.name);if(!t){console.warn("[OUID-Router]: No matched route name found");return}let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}if(e.absolute&&window.history.pushState({},"",e.path),e.path){let t=this.routes.find(n=>n.path===e.path);if(t){let n=H(t,e.params);window.history.pushState({},"",n),window.dispatchEvent(new PopStateEvent("popstate"));return}}}async beforeRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="before")){let o=await n.fn(e,t);if(o)return o}}async afterRouteGoing(e,t){for(let n of this.guards.filter(o=>o.type==="after")){let o=await n.fn(e,t);if(o)return o}}bind(e){let t=async()=>{console.log("Handling routing",this);let n=window.location.pathname,o=this.resolve(n);if(console.log("Matched::",o),!o){console.warn(`[Router] No route found for: ${n}`);return}let c=await this.beforeRouteGoing({url:n,path:n,name:o.route.name},e.inject(M));if(c){typeof c=="object"&&"name"in c&&this.push({name:c.name,params:c.params});return}let i=e.inject(g.PROVIDE_TOKEN),r=i.hostElement.querySelector("#router-view");console.log("Outlet",r),r&&(r.innerHTML="",e.provide(M,{params:o.params,query:o.query}),await i.mountComponent(r,o.route.component,i),await this.afterRouteGoing({url:n,path:n,name:o.route.name},e.inject(M)));};return window.addEventListener("popstate",t.bind(this)),t}unbind(e){window.removeEventListener("popstate",e);}beforeEach(e){let t={fn:e,type:"before"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}afterEach(e){let t={fn:e,type:"after"};return this.guards.push(t),()=>{this.guards.splice(this.guards.indexOf(t));}}};export{M as ACTIVE_ROUTE_TOKEN,R as App,_ as Component,T as Emits,O as OComponent,D as ROUTER_INJECTION_TOKEN,g as RenderContext,L as Router,w as RouterComponent,C as State,v as Stated,b as createComponent,Ce as createRouter,j as inject,E as isStated,de as provide,B as stated,V as useRouter};//# sourceMappingURL=index.mjs.map
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/emits.ts","../src/registry.ts","../src/state.ts","../src/component.ts","../src/style-injector.ts","../src/context.ts","../src/app.ts","../src/router/Router.ts"],"names":["Emits","events","event","args","handler","ComponentsRegistry","tag","compClass","key","componentsRegistry","Stated","value","isStated","ob","stated","target","state","proxify","seen","proxy","t","p","v","o","current","obj","State","data","oldValue","newValue","listener","path","now","Component","options","constructor","WithDecoration","createComponent","ctr","props","emits","OComponent","injectComponentStyles","css","styleEl","rejectComponentStyles","styleObj","toCamelCase","name","_","char","normaliseValue","toObjectWithFunctions","isLazyLoader","comp","RenderContext","_RenderContext","app","component","parentContext","frames","f","binding","directive","expr","strict","additionFrames","mergedFrame","frame","code","fn","error","b","k","d","show","e","oldChildren","newChildren","keyFn","val","idx","arr","last","keyedNode","node","localCtx","newCtx","keyed","classString","styleString","attr","controlled","placeholder","item","list","s","input","cc","child","matches","m","ignoredAttrs","a","hostNode","wrapper","handledProps","instance","children","slots","slot","rootEl","c","isProvideFunction","App","_App","root","token","plugin","selector","host","globalContext","provide","inject","RouterComponent","useRouter","__decorateClass","ROUTER_INJECTION_TOKEN","ACTIVE_ROUTE_TOKEN","createRouter","routes","Router","generatePath","route","params","RouteParser","parser","query","coll","tmps","r","match","to","from","guard","g","res","matched","guarded","context","outlet"],"mappings":"4BAAO,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,IAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,IAAMA,EAAN,KAA2C,CAC9C,WAAA,CAAoBC,CAAAA,CAAW,CAAX,IAAA,CAAA,MAAA,CAAAA,EACpB,CAEA,IAAA,CAAKC,KAAmBC,CAAAA,CAAW,CAC/B,IAAMC,CAAAA,CAAU,KAAK,MAAA,CAAOF,CAAK,CAAA,CAC9BE,CAAAA,EACCA,EAAQ,GAAGD,CAAI,EAEvB,CACJ,ECRA,IAAME,CAAAA,CAAN,KAAyB,CACb,WAAoD,IAAI,GAAA,CAChE,SAASC,CAAAA,CAAaC,CAAAA,CAAqC,CACvD,IAAMC,CAAAA,CAAMF,CAAAA,CAAI,iBAAA,GAChB,GAAG,IAAA,CAAK,UAAA,CAAW,GAAA,CAAIE,CAAG,CAAA,CAAG,CACzB,OAAA,CAAQ,IAAA,CAAK,YAAYA,CAAG,CAAA,6BAAA,CAA+B,EAC3D,MACJ,CACA,QAAQ,KAAA,CAAM,6BAAA,CAAgCF,CAAAA,CAAKC,CAAS,EAC5D,IAAA,CAAK,UAAA,CAAW,GAAA,CAAIC,CAAAA,CAAKD,CAAS,EACtC,CACA,UAAA,CAAWD,CAAAA,CAAa,CACpB,IAAME,CAAAA,CAAMF,EAAI,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AO,EAChD,CAEA,UAAA,CAAWkE,CAAAA,CAAsC,CAC/C,IAAM0E,EAAQ,CACZ,EAAA,CAAA1E,CAAAA,CACA,IAAA,CAAM,QACR,CAAA,CACA,OAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK0E,CAAK,CAAA,CACf,IAAM,CACX,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,KAAK,MAAA,CAAO,OAAA,CAAQA,CAAK,CAAC,EAC/C,CACF,CACA,SAAA,CAAU1E,CAAAA,CAAsC,CAC9C,IAAM0E,CAAAA,CAAQ,CACZ,EAAA,CAAA1E,CAAAA,CACA,IAAA,CAAM,OACR,CAAA,CACA,OAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK0E,CAAK,CAAA,CACf,IAAM,CACX,KAAK,MAAA,CAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,OAAA,CAAQA,CAAK,CAAC,EAC/C,CACF,CAEF","file":"index.mjs","sourcesContent":["export class Emits<O extends Record<string, any>> {\n constructor(private events: O) {\n }\n\n emit(event: keyof O, ...args: any) {\n const handler = this.events[event] as Function\n if(handler) {\n handler(...args)\n }\n }\n}","import { OComponentType } from \"./component\"\n\nclass ComponentsRegistry {\n private components: Map<string, OComponentType<any, any>> = new Map()\n register(tag: string, compClass: OComponentType<any, any>) {\n const key = tag.toLocaleLowerCase()\n if(this.components.has(key)) {\n console.warn(`[OUID] - ${key} component already registered`)\n return\n }\n console.debug('Registering new component: ' + tag, compClass)\n this.components.set(key, compClass)\n }\n unregister(tag: string) {\n const key = tag.toLocaleLowerCase()\n this.components.delete(key)\n }\n get(tag: string): OComponentType<any, any> {\n return this.components.get(tag.toLocaleLowerCase())\n }\n getAll() {\n return Array.from(this.components.entries())\n }\n}\nexport const componentsRegistry = new ComponentsRegistry()","export type StateWatcher<T> = <K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]) => void\nexport class Stated<T> {\n constructor(public value: T) { }\n}\nexport function isStated<T>(ob: any): ob is Stated<T> {\n return typeof ob === 'object' && !Array.isArray(ob) && 'value' in ob && ob instanceof Stated;\n}\nexport function stated<S, T>(target: T, state: State<S>): Stated<T> {\n const proxify = (target: any, seen: Map<any, any> = new Map()) => {\n if (seen.has(target)) {\n return seen[target]\n }\n const proxy = new Proxy(target, {\n set: (t, p, v) => {\n const o = t[p]\n if (typeof v === 'object') {\n t[p] = proxify(v)\n } else {\n t[p] = v\n }\n state.didChange(p as any, o, v)\n return true\n },\n get: (t, p) => {\n const v = Reflect.get(t, p)\n return v\n }\n })\n seen[target] = proxy\n for (let current = target; current; current = Object.getPrototypeOf(current)) {\n Object.keys(current).forEach(key => {\n const obj = target[key]\n if (typeof obj === 'object') {\n target[key] = proxify(obj, seen)\n }\n })\n }\n return proxy\n }\n if (typeof target === 'function') {\n throw new Error('Can\\'t create reactive element over a function')\n }\n if (typeof target !== 'object' && typeof target !== 'symbol') {\n return new Proxy(new Stated<T>(target), {\n set: (t, p, v) => {\n if (p !== 'value') throw new Error(`Undefined property ${String(p)} access`)\n const o = t[p]\n t[p] = v\n state.didChange(p as any, o, v)\n return true\n },\n get: (t, p) => {\n if (p !== 'value') throw new Error(`Undefined property ${String(p)} access`)\n return t[p]\n }\n })\n }\n\n return new Stated<T>(proxify(target))\n}\nexport class State<T extends Record<string, any>> {\n private THRESHOLD_TIME = 50\n private debounceTime = new Date().getTime()\n private state: T\n private listeners: StateWatcher<T>[] = []\n private timer = null\n constructor(data: T) {\n this.state = new Proxy(data, {\n set: (target, key: string, value: any) => {\n const oldValue = (target as any)[key];\n target[key as keyof T] = value\n this.didChange(key as keyof T, oldValue, value)\n return true\n },\n\n get: (target, key) => target[key as keyof T]\n }) as T\n }\n wrap<T>(obj: T): Stated<T> {\n return stated(obj, this)\n }\n has(key: keyof T): boolean {\n return key in this.state\n }\n setValue(key: keyof T, value: any) {\n this.state[key as keyof T] = value\n }\n getValue(key: keyof T): any {\n return this.state[key]\n }\n get value(): T {\n return this.state\n }\n\n private dispatchChanges<K extends keyof T>(key: K, oldValue: T[K], newValue: T[K]): void {\n for (const listener of this.listeners) {\n listener(key, oldValue, newValue)\n }\n }\n\n didChange(path: keyof T, oldValue: any, newValue: any) {\n const now = Date.now()\n if (now - this.debounceTime <= this.THRESHOLD_TIME) {\n clearTimeout(this.timer);\n }\n\n this.debounceTime = now;\n\n this.timer = setTimeout(() => {\n this.dispatchChanges(path, oldValue, newValue);\n }, this.THRESHOLD_TIME);\n }\n\n watch(listener: StateWatcher<T>) {\n this.listeners.push(listener)\n return this.listeners.length - 1\n }\n\n unwatch(listener: StateWatcher<T> | number) {\n if (typeof listener === \"number\") {\n this.listeners.splice(listener, 1)\n return\n }\n this.listeners.splice(this.listeners.indexOf(listener), 1)\n }\n}","import { Emits } from \"./emits\";\nimport { componentsRegistry } from \"./registry\";\nimport { State } from \"./state\"\nexport type ComponentProps <K extends Record<string, any>> = K\n\nexport function Component(options: {template: string, tag: string, use?: OComponentType[], css?: string}) {\n return function <T extends { new(...args: any[]): {} }>(constructor: T) {\n const WithDecoration = class extends constructor {\n template = options.template;\n css = options.css\n };\n console.log('Construct', options.css)\n\n const compClass = WithDecoration as unknown as ComponentConstructor<any, any>;\n\n componentsRegistry.register(options.tag, compClass);\n return WithDecoration;\n\n };\n}\nexport interface Component<P extends Record<string, any>, O extends Record<string, any>> {\n // template: string\n state: State<any>\n readonly emits: Emits<O>\n readonly props: ComponentProps<P>\n onMounted(): void\n willMount(): void\n willUnmount(): void\n provide<T>(key: string, value: T): void\n inject<T>(key: string): T | undefined\n}\n\nexport interface ComponentConstructor<P extends Record<string, any>, O extends Record<string, any>> {\n new(props?: P, emits?: O): Component<P, O>\n}\nexport function createComponent< P extends Record<string, any>, O extends Record<string, any>>(ctr: ComponentConstructor<P, O>, props?: P, emits?: O): Component<P, O> {\n return new ctr(props, emits)\n}\nexport class OComponent<P extends Record<string, any> = {}, O extends Record<string, any> = {}> implements Component<P, O> {\n // template: string = \"\"\n state: State<any>\n private parent?: OComponent<any, any> = undefined\n readonly emits: Emits<O>\n readonly props: ComponentProps<P>\n private provides: Map<string, any> = new Map();\n\n constructor(props: P = {} as P, emits: O = {} as O) {\n this.state = new State(this)\n this.props = props\n this.emits = new Emits(emits)\n }\n onMounted(): void {\n }\n willMount(): void {\n \n }\n willUnmount(): void {\n \n }\n /** Provide a value for descendants */\n provide<T>(key: string, value: T) {\n this.provides.set(key, value);\n }\n\n /** Inject a value from nearest ancestor */\n inject<T>(key: string): T | undefined {\n let current: OComponent<any, any> | undefined = this;\n while (current) {\n if (current.provides.has(key)) {\n return current.provides.get(key);\n }\n current = current.parent;\n }\n return undefined;\n }\n}\nexport type LazyLoader<P extends Record<string, any>, O extends Record<string, any>> = () => Promise<{ default: ComponentConstructor<P, O> }>;\nexport type OComponentType<P extends Record<string, any> = {}, O extends Record<string, any> = {}> = \n| ComponentConstructor<P, O>\n| LazyLoader<P, O>","export function injectComponentStyles(css: string): HTMLStyleElement {\n const styleEl = document.createElement('style')\n console.log('css:', css)\n styleEl.innerHTML = css\n document.head.appendChild(styleEl)\n return styleEl\n}\n\n\nexport function rejectComponentStyles(styleObj: HTMLStyleElement | undefined): void {\n if (!styleObj) {\n return;\n }\n document.head.removeChild(styleObj)\n}\n","import { Component, ComponentConstructor, createComponent, OComponent, OComponentType } from \"./component\";\nimport { App } from \"./app\";\nimport { isStated } from \"./state\";\nimport { componentsRegistry } from \"./registry\";\nimport { injectComponentStyles, rejectComponentStyles } from \"./style-injector\";\n\nfunction toCamelCase(name: string): string {\n return name.replace(/-([a-z])/g, (_, char) => char.toUpperCase());\n}\n\nfunction normaliseValue<T>(value: T) {\n if (isStated(value)) {\n return value.value as T\n }\n return value\n}\nfunction toObjectWithFunctions(obj: any) {\n const props: Record<string, any> = {};\n\n for (let current = obj; current; current = Object.getPrototypeOf(current)) {\n Object.getOwnPropertyNames(current).forEach(key => {\n const v = obj[key]\n if (typeof v === \"function\" && key !== \"constructor\" && !key.startsWith('__') && !key.endsWith('__')) {\n if (!(key in props)) {\n props[key] = (v as Function).bind(obj)\n }\n } else if (key !== \"constructor\" && !key.startsWith('__') && !key.endsWith('__')) {\n if (!(key in props)) {\n props[key] = v\n }\n }\n });\n }\n\n return props\n}\n\nfunction isLazyLoader<P, O>(\n comp: OComponentType<P>\n): comp is () => Promise<{ default: ComponentConstructor<P, O> }> {\n return typeof comp === \"function\" && !(\"prototype\" in comp);\n}\n\nexport class RenderContext {\n static PROVIDE_TOKEN = \"RENDER_CONTEXT\"\n private bindings: Binding[] = []\n private directives: Directive[] = []\n private mountedComponents: WeakMap<any, OComponent> = new WeakMap()\n stack: Record<string, any>[] = []\n\n constructor(private app: App, public component: OComponent, private parentContext: RenderContext | null, ...frames: Record<string, any>[]) {\n for (const f of frames) {\n this.stack.push(f)\n }\n }\n get hostElement(): HTMLElement {\n return this.component['_hostElement']\n }\n bind(binding: Binding) {\n this.bindings.push(binding)\n }\n directive(directive: Directive) {\n this.directives.push(directive)\n }\n evaluateExpression(expr: string): boolean {\n return this.resolve(expr)\n }\n resolve(key: string, strict: boolean = true, ...additionFrames: Record<string, any>[]) {\n const state = this.component.state.value\n const props = toObjectWithFunctions(state)\n const mergedFrame = { ...props }\n for (const frame of [...this.stack.toReversed(), ...additionFrames]) {\n Object.assign(mergedFrame, frame)\n }\n try {\n const code = `${strict ? '\"use strict\";' : ''}return ${key};`\n const fn = new Function(...Object.keys(mergedFrame), code);\n fn.bind(this.component)\n const exe = fn.apply(this.component, Object.values(mergedFrame));\n return exe\n } catch (error) {\n console.log(this)\n console.error(error)\n }\n return undefined\n }\n /** \n * Handing (o-model) like (ngModel) update, we should support mutliple syntaxe like o-mode=\"value\" where value is defined directly on the component\n * o-model=\"data['key']\" where data is either defined on the component, of in the enclosing scope in case of for-loop for instance\n * */\n updateValue(key: string, value: any) {\n const firstPart = key.split(/[\\.\\[]/)[0]\n // check if the first part is part of the component\n if (firstPart in this.component) {\n // we put this before the key and make resolution (which indeed make a dynamic function creation and execution)\n this.resolve(`this.${key}=__o_model_value__`, true, { '__o_model_value__': value })\n } else {\n this.resolve(`${key}=__o_model_value__`, true, { '__o_model_value__': value })\n }\n this.component.state.didChange('', '', '')\n // this.component.state.setValue(key, value)\n }\n\n push(frame: Record<string, any>) {\n this.stack.unshift(frame)\n }\n pop() {\n this.stack.shift()\n }\n\n // --- Interpolation & two-way binding ---\n updateBindings() {\n this.bindings.forEach(b => this.updateBinding(b));\n }\n updateBinding(binding: Binding) {\n if (binding.type === \"model\") {\n (binding.node as any).value = normaliseValue<string>(binding.context.resolve(binding.key));\n } else if (binding.type === 'interpolation') {\n binding.node.textContent = binding.template?.replace(/\\{\\{(.*?)\\}\\}/g, (_, k) => {\n k = k.trim();\n return normaliseValue(binding.context.resolve(k))\n }) ?? '';\n } else if (binding.type === 'attribute') {\n const name = binding.key\n const v = normaliseValue(this.resolve(binding.template))\n if (name === 'class') {\n // expand class\n this.expandClass(binding.node, v)\n } else if (name === 'style') {\n this.expandStyle(binding.node, v)\n } else if (typeof v !== 'object' && typeof v !== 'function' && typeof v !== 'symbol' && typeof v !== 'undefined') {\n binding.node.setAttribute(name, v.toString())\n }\n } else if(binding.type === 'prop' && binding.context.component) {\n const value = normaliseValue<string>(this.resolve(binding.template))\n try {\n console.log({...binding.context.component})\n binding.context.component.props[binding.key] = value\n binding.context.updateBindings()\n binding.context.updateDirectives()\n } catch (error) {\n console.error(error)\n }\n }\n }\n // --- Directives ---\n updateDirectives() {\n for (let d of this.directives) {\n if (d.type === \"if\") {\n let show = false;\n try {\n // show = new Function(...Object.keys(this.state), `return (${d.expr});`)\n // (...Object.values(this.state));\n show = d.context.evaluateExpression(d.expr)\n if (isStated<boolean>(show)) {\n show = show.value\n }\n } catch (e) {\n console.error('Error:', e)\n }\n if (show) {\n if (d.active !== true) {\n d.active = true;\n d.placeholder.after(d.node);\n d.context.render(d.node);\n d.context.updateBindings();\n }\n // d.context.updateDirectives()\n } else if (!show) {\n if (d.active !== false) {\n this.unmountComponent(d.node)\n d.node.remove();\n d.active = false;\n }\n }\n }\n\n if (d.type === \"for\") {\n console.log('Start for directive', d)\n const oldChildren: Map<any, {node: ChildNode, ctx: RenderContext}> = d.children ?? new Map()\n const newChildren: Map<any, {node: ChildNode, ctx: RenderContext}> = new Map()\n const keyFn = (val, idx) => d.key ? normaliseValue<any>(d.context.resolve(d.key, true, { [d.item!]: val })) : idx\n\n let arr = normaliseValue<any[]>(d.context.resolve(d.list!)) || [];\n console.log('For-directive', arr)\n let last: ChildNode = d.placeholder\n arr.forEach(async (val, idx) => {\n const key = keyFn(val, idx)\n const keyedNode = oldChildren.get(key)\n let node = keyedNode?.node\n let localCtx = { [d.item!]: val };\n const newCtx = keyedNode?.ctx ?? new RenderContext(this.app, this.component, null)\n newCtx.stack = [localCtx, ...d.context.stack]\n if (!node) {\n // create new node\n node = d.node.cloneNode(true) as ChildNode;\n newCtx.render(node);\n last.after(node);\n newCtx.updateBindings();\n newCtx.updateDirectives();\n } else {\n newCtx.updateBindings();\n newCtx.updateDirectives();\n }\n last = node\n newChildren.set(key, {node, ctx: newCtx})\n });\n // remove old nodes not in new list\n oldChildren.forEach((keyed, key) => {\n if (!newChildren.has(key)) {\n this.unmountComponent(keyed.node as Element);\n keyed.node.remove();\n }\n });\n d.children = newChildren\n }\n }\n }\n\n private render(node: Node) {\n switch (node.nodeType) {\n case Node.TEXT_NODE:\n this.handleTextNode(node as HTMLElement)\n break\n case Node.ELEMENT_NODE:\n this.handleElementNode(node as HTMLElement)\n break\n default:\n console.warn(\"Unknown node\", node)\n }\n }\n private expandClass(node: HTMLElement, value: any) {\n let classString = value\n if (typeof value === 'object') {\n if (Array.isArray(value)) {\n classString = value.join(' ')\n } else {\n classString = Object.keys(value).filter(e => value[e]).join(' ')\n }\n }\n node.setAttribute('class', classString)\n }\n private expandStyle(node: HTMLElement, value: any) {\n let styleString = value\n if (typeof value === 'object' && !Array.isArray(value)) {\n styleString = Object.keys(value).map(e => `${e}: ${value[e]}`).join(';')\n }\n node.setAttribute('style', styleString)\n }\n private expandStandardAttributes(node: HTMLElement) {\n\n [...node.attributes].filter(attr => attr.name.startsWith(':')).filter(attr => [':id', ':style', ':class', ':placeholder'].includes(attr.name)).forEach(attr => {\n const key = attr.name.substring(1)\n this.bind({\n type: 'attribute',\n node,\n key,\n context: this,\n template: attr.value.trim()\n })\n node.removeAttribute(attr.name)\n })\n }\n handleElementNode(node: HTMLElement) {\n // expand style and classes\n\n let controlled: 'for' | 'if' | null = null\n // *if directive\n if (node.hasAttribute(\"o-if\")) {\n const expr = node.getAttribute(\"o-if\")!;\n const placeholder = document.createComment(\"o-if:\" + expr);\n node.parentNode?.insertBefore(placeholder, node);\n node.removeAttribute(\"o-if\");\n this.directive({\n type: \"if\",\n expr,\n node,\n placeholder,\n context: this,\n active: undefined\n });\n controlled = 'if'\n }\n\n // *for directive\n if (node.hasAttribute(\"o-for\")) {\n if (controlled === 'if') {\n throw new Error('Can\\'t have o-if and o-for on the same component')\n }\n const expr = node.getAttribute(\"o-for\")!;\n const [item, list] = expr.split(\" of \").map(s => s.trim());\n const placeholder = document.createComment(\"for:\" + expr);\n const key = node.getAttribute(':key')\n node.parentNode?.insertBefore(placeholder, node);\n node.removeAttribute(\"o-for\");\n node.removeAttribute(':key')\n node.remove();\n this.directive({\n type: \"for\",\n item,\n list,\n node,\n placeholder,\n context: this,\n key,\n });\n controlled = 'for'\n }\n if (controlled !== 'for') {\n // Two-way binding [(model)]\n [...node.attributes].forEach(attr => {\n if (attr.name === 'o-model') {\n const key = attr.value.trim();\n if (node.tagName === \"INPUT\" || node.tagName === \"TEXTAREA\") {\n const input = node as HTMLInputElement | HTMLTextAreaElement\n input.value = normaliseValue(this.resolve(key,));\n input.addEventListener(\"input\", (e) => {\n // this.state[key] = (e.target as any).value;\n const value = (e.target as any).value\n this.updateValue(key, value)\n\n });\n this.bind({ node, key, type: \"model\", context: this });\n }\n node.removeAttribute(attr.name);\n }\n });\n }\n\n\n const tag = node.tagName.toLowerCase();\n const cc = componentsRegistry.get(tag)\n let props = {} as any, events = {} as any\n if (controlled !== 'for') {\n const { props: p, events: e } = this.componentAttributes(node, this)\n props = p\n events = e\n this.expandStandardAttributes(node)\n }\n // Event binding @(event)=\"fn()\"\n Object.keys(events).forEach(k => {\n const handler = events[k]\n node.addEventListener(k, e => {\n if (typeof handler === \"function\") (handler as Function).apply(this.component, [e]);\n });\n node.removeAttribute('@' + k);\n });\n if (controlled) {\n return\n }\n\n if (cc) {\n this.mountComponent(node, cc, this, props, events);\n return; // stop scanning original node\n }\n [...node.childNodes].forEach(child => this.render(child as HTMLElement));\n }\n handleTextNode(node: HTMLElement) {\n const matches = node.textContent?.match(/\\{\\{(.*?)\\}\\}/g);\n if (matches) {\n matches.forEach(m => {\n const key = m.replace(/[{}]/g, \"\").trim();\n this.bind({ type: 'interpolation', node, key, template: node.textContent, context: this });\n });\n }\n }\n private componentAttributes(node: HTMLElement, parentContext: RenderContext | null) {\n const props: Record<string, { name: string, expr?: string, value: any }> = {};\n const events: any = {};\n const ignoredAttrs = ['import', 'interface', 'module', 'o-model', 'o-if', 'o-for'];\n [...node.attributes].filter(a => !ignoredAttrs.includes(a.name)).forEach(attr => {\n let name = attr.name\n if (name.startsWith('@')) {\n // attach an event\n const handler = parentContext?.resolve(attr.value, true)\n if (typeof handler !== 'function') {\n throw new Error('Event handler can only be function')\n }\n name = name.substring(1)\n events[name] = handler\n return\n }\n let expr: string | null = null\n let p: any = attr.value\n if (name.startsWith(':')) {\n expr = attr.value\n name = name.substring(1)\n p = parentContext?.resolve(attr.value)\n if (isStated(p)) {\n p = p.value\n } // ????\n }\n name = toCamelCase(name)\n props[name] = {\n name,\n value: p,\n expr\n };\n });\n return { props, events }\n }\n async mountComponent<T, O>(hostNode: HTMLElement, component: OComponentType<T, O>, parentContext: RenderContext, props: Record<string, { name: string, value: any, expr?: string }> = {}, emits: O = {} as O) {\n // Props from attributes\n // const { props, events } = this.componentAttributes(hostNode, parentContext);\n const wrapper = document.createElement('div');\n const newCtx = new RenderContext(this.app, null, null)\n const handledProps = {} as T\n Object.keys(props).forEach(k => {\n const p = props[k]\n if (p.expr) {\n // create a binding\n this.bind({\n type: 'prop',\n node: wrapper,\n key: k,\n context: newCtx,\n template: p.expr\n })\n }\n handledProps[k] = p.value\n })\n\n const instance = await RenderContext.h(component, handledProps, emits);\n newCtx.component = instance\n newCtx.stack = [instance.props]\n Object.keys(props).filter(e => !props[e].expr).forEach(attr => wrapper.setAttribute(attr, props[attr].value))\n wrapper.classList.add('o-component-host')\n if (hostNode.tagName.toLowerCase() !== 'div') {\n wrapper.classList.add('c-' + hostNode.tagName.toLowerCase())\n }\n instance.willMount()\n wrapper.innerHTML = instance['template'].trim();\n if (instance['css']) {\n instance['cssInstance'] = injectComponentStyles(instance['css'])\n }\n // append css if any \n const children = Array.from(hostNode.childNodes)\n const slots = wrapper.querySelectorAll('o-slot')\n if (slots) {\n // there are some slot, so we make injections\n slots.forEach(slot => {\n const name = slot.getAttribute('name')\n children.filter(e => {\n if (!name) {\n return e.nodeType !== Node.ELEMENT_NODE || !(e as Element).hasAttribute('slot')\n }\n return name && e.nodeType === Node.ELEMENT_NODE && (e as Element).getAttribute('slot') === name\n }).forEach(node => slot.parentNode?.insertBefore(node, slot))\n })\n }\n const rootEl = wrapper;\n // this.unmountComponent(hostNode)\n hostNode.innerHTML = \"\"\n hostNode.appendChild(wrapper)\n \n instance.state.watch(() => {\n newCtx.updateBindings();\n newCtx.updateDirectives();\n })\n instance['_hostElement'] = rootEl\n instance['parent'] = parentContext?.component ?? undefined\n instance.provide(RenderContext.PROVIDE_TOKEN, this)\n // attach rootEl to this component\n newCtx.render(rootEl);\n newCtx.updateBindings();\n newCtx.updateDirectives();\n this.mountedComponents.set(rootEl, instance)\n instance.onMounted()\n }\n unmountComponent(node: Element) {\n const comp = this.mountedComponents.get(node)\n if (comp) {\n // emit will unmount\n rejectComponentStyles(comp['cssInstance'])\n comp.willUnmount()\n comp['_hostElement'] = null\n }\n node.querySelectorAll('*').forEach(child => {\n this.unmountComponent(child)\n })\n this.mountedComponents.delete(node)\n }\n static h<P, O>(component: ComponentConstructor<P, O>, props: P, emits?: O): OComponent<P>;\n static async h<P, O>(component: OComponentType<P>, props: P, emits?: O): Promise<OComponent<P>>\n\n\n static h<P, O>(component: OComponentType<P, O>, props: P, emits?: O): Component<P, O> | Promise<Component<P, O>> {\n if (isLazyLoader(component)) {\n return component().then((c) => createComponent(c.default, props, emits))\n } else {\n return createComponent(component, props, emits);\n }\n }\n}\nexport type Binding = { type: 'model' | 'interpolation' | 'attribute' | 'prop', node: HTMLElement, key: string, template?: string | null, context: RenderContext }\nexport type Directive = { type: 'if' | 'for', node: HTMLElement, expr?: string, placeholder: Comment, context: RenderContext, active?: boolean, list?: string, item?: string, children?: Map<any, {node: ChildNode, ctx: RenderContext}>, key?: string }\n","import { ComponentConstructor, createComponent, OComponent, OComponentType } from \"./component\";\nimport { RenderContext } from \"./context\";\n\n\n\ntype ProvideFunction<T> = () => T\nexport type Provider<T = any> = {\n value?: T,\n provide?: ProvideFunction<T>\n}\nfunction isProvideFunction<T>(fn: T | ProvideFunction<T>): fn is ProvideFunction<T> {\n return typeof fn === 'function'\n}\nexport interface Plugin {\n install(app: App): void\n}\n/** Injection token key */\nexport type InjectionKey = string\n/** Providers type */\nexport type Providers = Map<InjectionKey, Provider>\n/**\n * OUIDesigner App\n */\nexport class App {\n static currentApp: App | null = null\n private providers: Providers = new Map()\n /**\n * Provide a value through a key to all the app globally\n * @param token the registration key\n * @param value the provider value\n */\n provide<T>(token: InjectionKey, value: T | (() => T)): void {\n if (this.providers.has(token)) {\n console.warn(`[OUID] - Provider ${token} already exists`)\n return\n }\n this.providers.set(token, isProvideFunction(value) ? { provide: value } : { value: value })\n }\n /**\n * Get globally a provider through a given key\n * @param token the key to look up globally\n * @returns a provider value\n */\n inject<T>(token: InjectionKey): T {\n return this.providers.get(token).value as T\n }\n /**\n * Register a plugin to be used by this app\n * @param plugin the plugin to register\n * @returns `this` App instance\n */\n use(plugin: Plugin) {\n plugin.install(this)\n return this\n }\n private host: HTMLElement\n constructor(private root: ComponentConstructor<any, any>) {\n App.currentApp = this\n }\n /**\n * Mount the App in a host element\n * @param selector the host element where the app's root component should be mounted\n */\n mount(selector: string) {\n const host = document.getElementById(selector)\n if (!host) throw new Error(\"No selector found for \" + selector)\n this.host = host\n\n const globalContext = new RenderContext(this, null, null)\n globalContext.mountComponent(this.host, this.root, null).then(() => {\n globalContext.updateBindings()\n globalContext.updateDirectives()\n })\n }\n}\n\n/**\n * Provide a value through a key to all the app globally\n * @param token the registration key\n * @param value the provider value\n */\nexport function provide<T>(token: InjectionKey, value: T | (() => T)): void {\n App.currentApp.provide(token, value)\n}\n/**\n * Get globally a provider through a given key\n * @param token the key to look up globally\n * @returns a provider value\n */\nexport function inject<T>(token: InjectionKey): T {\n return App.currentApp.inject(token)\n}","import RouteParser from 'route-parser'\nimport { App, inject, Plugin } from '../app'\nimport { Component, OComponent, OComponentType } from '../component'\nimport { RenderContext } from '../context'\n/**\n * Component responsible for display routes\n * Usage: <o-router></o-router>\n */\n@Component({\n tag: 'o-router',\n template: `\n <div id=\"router-view\"></div>\n `\n})\nexport class RouterComponent extends OComponent {\n private routeStateHander: (() => void) | null = null\n private router: Router\n willMount(): void {\n }\n onMounted(): void {\n this.router = useRouter()\n console.log('Router mounted')\n this.routeStateHander = this.router.bind(this)\n this.routeStateHander();\n }\n willUnmount(): void {\n console.log('Router will unmount')\n this.router.unbind(this.routeStateHander);\n }\n}\nexport const ROUTER_INJECTION_TOKEN = \"OROUTER_TOKEN\"\nexport const ACTIVE_ROUTE_TOKEN = \"ACTIVE_ROUTE\"\nexport interface Route {\n path?: string\n name: string\n component?: OComponentType,\n redirectTo?: string\n}\n\nexport function useRouter(): Router {\n return inject<Router>(ROUTER_INJECTION_TOKEN)\n}\nexport function createRouter(routes: Routes): Router {\n return new Router(routes)\n}\nexport type Routes = Array<Route>\nfunction generatePath(route: Route, params: Record<string, string>): string {\n let path = new RouteParser(route.path).reverse(params)\n if (path === false) return \"\"\n return path\n}\ntype MatchedRoute = { route: Route, params: Record<string, any>, query: Record<string, string> }\nexport type Promised<T> = T | Promise<T>\nexport type RouteLocationNamed = {name: string, params?: Record<string, any>}\nexport type RouteGuardReturn = void | boolean | RouteLocationNamed\nexport type RouteGaurdFunction = (to: {url: string, path: string, name: string }, from?: {query: Record<string, string>, params: Record<string, string>}) => Promised<RouteGuardReturn>\nexport interface RouteGuard {\n type: 'before' | 'after',\n fn: RouteGaurdFunction\n}\nexport class Router implements Plugin {\n private guards: Array<RouteGuard> = []\n constructor(public routes: Routes) {\n }\n install(app: App) {\n app.provide(ROUTER_INJECTION_TOKEN, this)\n }\n resolve(path: string): MatchedRoute {\n const parser = new RouteParser(path)\n const query: Record<string, string> = path.split('?').reverse()[0].split('&').reduce((coll, value) => {\n const tmps = value.split('=')\n coll[tmps[0]] = decodeURIComponent(tmps[1])\n return coll\n }, {})\n for (const r of this.routes) {\n const match = parser.match(r.path)\n if (match) {\n return {\n route: r,\n params: match,\n query\n }\n }\n }\n return null\n }\n push(options: { name?: string, path?: string, params?: Record<string, string>, absolute?: boolean }): void {\n if (!options.path && !options.name) {\n console.warn('[OUID-Router]: no path or name provided to push')\n return\n }\n\n if (options.name) {\n const route = this.routes.find(r => r.name === options.name)\n if (!route) {\n console.warn('[OUID-Router]: No matched route name found')\n return\n }\n const path = generatePath(route, options.params)\n window.history.pushState({}, \"\", path);\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n return\n }\n if (options.absolute) {\n window.history.pushState({}, \"\", options.path);\n }\n if (options.path) {\n // first try to match direct path\n const route = this.routes.find(r => r.path === options.path)\n if (route) {\n const path = generatePath(route, options.params)\n window.history.pushState({}, \"\", path);\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n return\n }\n }\n\n }\n\n private async beforeRouteGoing(to: {url: string, path: string, name: string }, from: { params: Record<string, any>, query: Record<string, any> }): Promise<RouteGuardReturn> {\n for (const guard of this.guards.filter(g => g.type === 'before')) {\n const res = await guard.fn(to, from)\n if (res) {\n return res\n }\n }\n return\n }\n private async afterRouteGoing(to: {url: string, path: string, name: string }, from: { params: Record<string, any>, query: Record<string, any> }): Promise<RouteGuardReturn> {\n for (const guard of this.guards.filter(g => g.type === 'after')) {\n const res = await guard.fn(to, from)\n if (res) {\n return res\n }\n }\n return\n }\n\n bind(component: RouterComponent): (() => void) {\n const handler = async () => {\n console.log('Handling routing', this)\n const path = window.location.pathname;\n const matched = this.resolve(path);\n console.log('Matched::', matched)\n if (!matched) {\n console.warn(`[Router] No route found for: ${path}`);\n return;\n }\n const guarded = await this.beforeRouteGoing({url: path, path, name: matched.route.name}, component.inject(ACTIVE_ROUTE_TOKEN))\n if (guarded) {\n if(typeof guarded === 'object' && 'name' in guarded) {\n // redirection\n this.push({name: guarded.name, params: guarded.params})\n }\n return;\n }\n const context = component.inject<RenderContext>(RenderContext.PROVIDE_TOKEN)\n const outlet = context.hostElement.querySelector(\"#router-view\") as HTMLElement | null;\n console.log('Outlet', outlet)\n if (!outlet) return;\n outlet.innerHTML = \"\"; // clear previous\n component.provide(ACTIVE_ROUTE_TOKEN, {\n params: matched.params,\n query: matched.query\n })\n await context.mountComponent(outlet, matched.route.component, context)\n await this.afterRouteGoing({url: path, path, name: matched.route.name}, component.inject(ACTIVE_ROUTE_TOKEN))\n\n }\n window.addEventListener('popstate', handler.bind(this))\n return handler\n }\n\n unbind(handler: () => void) {\n window.removeEventListener('popstate', handler)\n }\n\n beforeEach(fn: RouteGaurdFunction): (() => void) {\n const guard = {\n fn,\n type: 'before'\n } as RouteGuard\n this.guards.push(guard)\n return () => {\n this.guards.splice(this.guards.indexOf(guard))\n }\n }\n afterEach(fn: RouteGaurdFunction): (() => void) {\n const guard = {\n fn,\n type: 'after'\n } as RouteGuard\n this.guards.push(guard)\n return () => {\n this.guards.splice(this.guards.indexOf(guard))\n }\n }\n\n}"]}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "ouider",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "build": "tsup"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "MIT",
11
+ "description": "OUIDesigner render framework core package, including a router",
12
+ "devDependencies": {
13
+ "@types/route-parser": "^0.1.7",
14
+ "tsup": "^8.5.0",
15
+ "typescript": "^5.9.2"
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "files": [
24
+ "/dist"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "dependencies": {
30
+ "route-parser": "^0.0.5"
31
+ }
32
+ }