@actdim/dynstruct 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/appDomain/appContracts.d.ts +3 -3
  2. package/dist/appDomain/appContracts.d.ts.map +1 -1
  3. package/dist/appDomain/appContracts.es.js.map +1 -1
  4. package/dist/appDomain/security/securityContracts.d.ts +1 -1
  5. package/dist/appDomain/security/securityContracts.d.ts.map +1 -1
  6. package/dist/appDomain/security/securityContracts.es.js.map +1 -1
  7. package/dist/appDomain/security/securityProvider.d.ts +1 -1
  8. package/dist/appDomain/security/securityProvider.d.ts.map +1 -1
  9. package/dist/appDomain/security/securityProvider.es.js +62 -62
  10. package/dist/appDomain/security/securityProvider.es.js.map +1 -1
  11. package/dist/componentModel/DynamicContent.d.ts +2 -2
  12. package/dist/componentModel/DynamicContent.d.ts.map +1 -1
  13. package/dist/componentModel/DynamicContent.es.js +1 -1
  14. package/dist/componentModel/DynamicContent.es.js.map +1 -1
  15. package/dist/componentModel/adapters.d.ts +13 -7
  16. package/dist/componentModel/adapters.d.ts.map +1 -1
  17. package/dist/componentModel/adapters.es.js +22 -17
  18. package/dist/componentModel/adapters.es.js.map +1 -1
  19. package/dist/componentModel/componentContext.d.ts.map +1 -1
  20. package/dist/componentModel/componentContext.es.js +58 -56
  21. package/dist/componentModel/componentContext.es.js.map +1 -1
  22. package/dist/componentModel/contracts.d.ts +173 -4
  23. package/dist/componentModel/contracts.d.ts.map +1 -1
  24. package/dist/componentModel/contracts.es.js +11 -1
  25. package/dist/componentModel/contracts.es.js.map +1 -1
  26. package/dist/componentModel/core.d.ts +17 -0
  27. package/dist/componentModel/core.d.ts.map +1 -0
  28. package/dist/componentModel/core.es.js +162 -0
  29. package/dist/componentModel/core.es.js.map +1 -0
  30. package/dist/componentModel/react.d.ts +5 -0
  31. package/dist/componentModel/react.d.ts.map +1 -0
  32. package/dist/componentModel/react.es.js +201 -0
  33. package/dist/componentModel/react.es.js.map +1 -0
  34. package/dist/net/client.d.ts +2 -1
  35. package/dist/net/client.d.ts.map +1 -1
  36. package/dist/net/client.es.js +46 -45
  37. package/dist/net/client.es.js.map +1 -1
  38. package/dist/services/NavService.d.ts +1 -1
  39. package/dist/services/NavService.d.ts.map +1 -1
  40. package/dist/services/NavService.es.js +9 -9
  41. package/dist/services/NavService.es.js.map +1 -1
  42. package/dist/services/StorageService.d.ts +4 -3
  43. package/dist/services/StorageService.d.ts.map +1 -1
  44. package/dist/services/StorageService.es.js +15 -15
  45. package/dist/services/StorageService.es.js.map +1 -1
  46. package/package.json +8 -7
  47. package/dist/componentModel/componentModel.d.ts +0 -165
  48. package/dist/componentModel/componentModel.d.ts.map +0 -1
  49. package/dist/componentModel/componentModel.es.js +0 -343
  50. package/dist/componentModel/componentModel.es.js.map +0 -1
@@ -0,0 +1,162 @@
1
+ import { isObservable as k, runInAction as I, toJS as y, autorun as m } from "mobx";
2
+ import { $isBinding as p, ComponentMsgFilter as b } from "./contracts.es.js";
3
+ function x(e) {
4
+ return e[p] === !0;
5
+ }
6
+ function P(e, c, r, t) {
7
+ return {
8
+ get: e,
9
+ set: c,
10
+ converter: r,
11
+ validator: t,
12
+ readOnly: !!c,
13
+ [p]: !0
14
+ };
15
+ }
16
+ function w(e, c) {
17
+ return {
18
+ get: () => e()[c],
19
+ set: (r) => {
20
+ e()[c] = r;
21
+ },
22
+ [p]: !0
23
+ };
24
+ }
25
+ const C = /* @__PURE__ */ new WeakMap();
26
+ function F(e, c, r) {
27
+ if (typeof e != "object" || e === null || !k(e))
28
+ return e;
29
+ if (C.has(e))
30
+ return C.get(e);
31
+ const t = new Proxy(e, {
32
+ get(o, n, s) {
33
+ const i = r[n]?.onGet;
34
+ if (i) return i();
35
+ const f = c.get(n);
36
+ if (f?.get)
37
+ return f.get();
38
+ const u = Reflect.get(o, n, s);
39
+ return typeof u == "object" && u !== null && k(u) ? F(u, c, r) : u;
40
+ },
41
+ set(o, n, s, i) {
42
+ const f = o[n], u = r[n]?.onChanging;
43
+ if (u && u(f, s) === !1 || r.onPropChanging && r.onPropChanging(n, f, s) === !1)
44
+ return !0;
45
+ const d = I(() => Reflect.set(o, n, s, i));
46
+ return c.get(n)?.set?.(s), r[n]?.onChange?.(s), r.onPropChange?.(n, s), d;
47
+ }
48
+ });
49
+ return C.set(e, t), t;
50
+ }
51
+ function B(e) {
52
+ return e.split("/").filter(Boolean).map((o) => decodeURIComponent(o)).join("-").normalize("NFKD").replace(/[^a-zA-Z0-9\-_:.+#]/g, "-").replace(/-+/g, "-").replace(/^[^a-zA-Z]+/, "-").replace(/[+#]$/, "-");
53
+ }
54
+ function E(e = 2) {
55
+ const r = new Error().stack?.split(`
56
+ `);
57
+ if (!r || r.length <= e)
58
+ return null;
59
+ const o = r[e].match(/\(([^)]+)\)/)?.[1];
60
+ return o && document.querySelector('script[type="module"][src*="/@vite/"]') && globalThis.CONFIG_TYPE === "DEVELOPMENT" ? o.replace(/\?[^:]+/, "") : o;
61
+ }
62
+ function N(e = 2) {
63
+ const r = new Error().stack?.split(`
64
+ `);
65
+ if (!r || r.length <= e)
66
+ return null;
67
+ const o = r[e].trim().match(/^at\s+([^\s(]+)/);
68
+ if (!o)
69
+ return null;
70
+ const n = o[1], s = n.match(/^use(.+)/);
71
+ return s ? s[1] : n;
72
+ }
73
+ function j(e) {
74
+ const c = e?.msgBroker.provide;
75
+ if (c)
76
+ for (const [t, o] of Object.entries(c))
77
+ for (const [n, s] of Object.entries(o)) {
78
+ const i = s, f = i.callback;
79
+ f && (i.callback = (a, l) => f(a, l, e));
80
+ const u = i.filter, d = i.componentFilter || b.None, g = (a) => {
81
+ let l = !0;
82
+ return d & b.FromAncestors && (l = e.getChainUp().indexOf(a.headers?.sourceId) >= 0), l && d & b.FromDescendants && (l = e.getChainDown().indexOf(a.headers?.sourceId) >= 0), l && u && (l = u(a, e)), l;
83
+ };
84
+ i.filter = g, e.msgBus.provide({
85
+ ...s,
86
+ channel: t,
87
+ group: n,
88
+ options: {
89
+ abortSignal: e.msgBroker.abortController.signal
90
+ }
91
+ });
92
+ }
93
+ const r = e?.msgBroker?.subscribe;
94
+ if (r)
95
+ for (const [t, o] of Object.entries(r))
96
+ for (const [n, s] of Object.entries(o)) {
97
+ const i = s, f = i.callback;
98
+ f && (i.callback = (a) => f(a, e));
99
+ const u = i.filter, d = i.componentFilter || b.None, g = (a) => {
100
+ let l = !0;
101
+ return d & b.FromAncestors && (l = e.getChainUp().indexOf(a.headers?.sourceId) >= 0), l && d & b.FromDescendants && (l = e.getChainDown().indexOf(a.headers?.sourceId) >= 0), l && u && (l = u(a, e)), l;
102
+ };
103
+ i.filter = g, e.msgBus.on({
104
+ ...s,
105
+ channel: t,
106
+ group: n,
107
+ config: {
108
+ abortSignal: e.msgBroker.abortController.signal
109
+ }
110
+ });
111
+ }
112
+ }
113
+ function D(e, c) {
114
+ const r = (t) => {
115
+ t.payload != null && (t.payload = structuredClone(y(t.payload))), t.headers || (t.headers = {}), c?.(t.headers);
116
+ };
117
+ return {
118
+ config: e.config,
119
+ on: (t) => e.on(t),
120
+ once: (t) => e.once(t),
121
+ stream: (t) => e.stream(t),
122
+ provide: (t) => (r(t), e.provide(t)),
123
+ send: (t) => (r(t), e.send(t)),
124
+ request: (t) => (r(t), e.request(t))
125
+ };
126
+ }
127
+ function M(e, c, r) {
128
+ let t = null, o = !1, n;
129
+ const s = () => {
130
+ t || (t = m(
131
+ () => {
132
+ if (!o) {
133
+ const g = r(e);
134
+ typeof g == "function" && (g(), n = g);
135
+ }
136
+ },
137
+ { name: `effect:${c}` }
138
+ ));
139
+ }, i = () => {
140
+ t?.(), t = null, n && (n(), n = void 0);
141
+ }, f = () => {
142
+ o = !0;
143
+ }, u = () => {
144
+ o = !1;
145
+ }, d = () => {
146
+ i(), s();
147
+ };
148
+ return s(), { start: s, pause: f, resume: u, stop: i, restart: d };
149
+ }
150
+ export {
151
+ P as bind,
152
+ w as bindProp,
153
+ M as createEffect,
154
+ F as createRecursiveProxy,
155
+ D as getComponentMsgBus,
156
+ N as getComponentNameByCaller,
157
+ E as getComponentSourceByCaller,
158
+ x as isBinding,
159
+ j as registerMsgBroker,
160
+ B as toHtmlId
161
+ };
162
+ //# sourceMappingURL=core.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.es.js","sources":["../../src/componentModel/core.tsx"],"sourcesContent":["import React from 'react';\r\nimport { MsgBus } from '@actdim/msgmesh/contracts';\r\nimport { isObservable, runInAction, toJS, autorun, IReactionDisposer } from 'mobx';\r\nimport type {\r\n Binding,\r\n Component,\r\n ComponentMsgHeaders,\r\n ComponentStruct,\r\n EffectController,\r\n EffectFn,\r\n MsgChannelGroupProviderParams,\r\n MsgChannelGroupSubscriberParams,\r\n PropEventHandlers,\r\n PropValueChangeHandler,\r\n PropValueChangingHandler,\r\n Validator,\r\n ValueConverter,\r\n} from './contracts';\r\nimport { $isBinding, ComponentMsgFilter } from './contracts';\r\nimport { isPlainObject } from 'mobx/dist/internal';\r\n\r\nconst blankView = () => null;\r\n\r\nexport function isBinding(obj: any): obj is Binding {\r\n return obj[$isBinding] === true;\r\n}\r\n\r\nexport function bind<T, TFrom = any>(\r\n get: () => T,\r\n set?: (value: T) => void,\r\n converter?: ValueConverter<T, TFrom>,\r\n validator?: Validator<T>,\r\n): Binding {\r\n return {\r\n get: get,\r\n set: set,\r\n converter: converter,\r\n validator: validator,\r\n readOnly: !!set,\r\n [$isBinding]: true,\r\n };\r\n}\r\n\r\nexport function bindProp<T extends object, P extends keyof T>(target: () => T, prop: P): Binding {\r\n return {\r\n get: () => target()[prop],\r\n set: (value: T[P]) => {\r\n target()[prop] = value;\r\n },\r\n [$isBinding]: true,\r\n };\r\n}\r\n\r\nconst proxyCache = new WeakMap<object, any>();\r\n\r\nexport type ProxyEventHandlers = {\r\n onPropChanging?: PropValueChangingHandler<PropertyKey>;\r\n onPropChange?: PropValueChangeHandler<PropertyKey>;\r\n} & Record<PropertyKey, PropEventHandlers>;\r\n\r\nexport function createRecursiveProxy(\r\n target: any,\r\n bindings: Map<PropertyKey, Binding>,\r\n handlers: ProxyEventHandlers,\r\n) {\r\n if (typeof target !== 'object' || target === null) {\r\n return target;\r\n }\r\n\r\n // isPlainObject\r\n if (!isObservable(target)) {\r\n return target;\r\n }\r\n\r\n if (proxyCache.has(target)) {\r\n return proxyCache.get(target);\r\n }\r\n\r\n const proxy = new Proxy(target, {\r\n get(obj, prop, receiver) {\r\n // 1. custom handlers\r\n const onGet = handlers[prop]?.onGet;\r\n if (onGet) return onGet();\r\n\r\n // 2. bindings\r\n const binding = bindings.get(prop);\r\n if (binding?.get) {\r\n return binding.get();\r\n }\r\n\r\n const value = Reflect.get(obj, prop, receiver);\r\n\r\n if (typeof value === 'object' && value !== null && isObservable(value)) {\r\n return createRecursiveProxy(value, bindings, handlers);\r\n }\r\n\r\n return value;\r\n },\r\n\r\n set(obj, prop, value, receiver) {\r\n const oldValue = obj[prop];\r\n\r\n // before-change hooks\r\n const onChanging = handlers[prop]?.onChanging;\r\n if (onChanging && onChanging(oldValue, value) === false) {\r\n return true;\r\n }\r\n\r\n if (\r\n handlers.onPropChanging &&\r\n handlers.onPropChanging(prop, oldValue, value) === false\r\n ) {\r\n return true;\r\n }\r\n\r\n const result = runInAction(() => {\r\n return Reflect.set(obj, prop, value, receiver);\r\n });\r\n\r\n // bindings\r\n const binding = bindings.get(prop);\r\n binding?.set?.(value);\r\n\r\n // after-change hooks\r\n handlers[prop]?.onChange?.(value);\r\n handlers.onPropChange?.(prop, value);\r\n\r\n return result;\r\n },\r\n });\r\n\r\n proxyCache.set(target, proxy);\r\n return proxy;\r\n}\r\n\r\nexport function toHtmlId(url: string): string {\r\n let parts = url\r\n .split('/')\r\n .filter(Boolean)\r\n .map((segment) => decodeURIComponent(segment));\r\n\r\n const raw = parts.join('-');\r\n // sanitize\r\n let id = raw\r\n .normalize('NFKD')\r\n .replace(/[^a-zA-Z0-9\\-_:.+#]/g, '-')\r\n .replace(/-+/g, '-')\r\n .replace(/^[^a-zA-Z]+/, '-')\r\n // .replace(/:/g, '-')\r\n // .replace(/\\./g, '_')\r\n // .replace(/#/g, '-')\r\n .replace(/[+#]$/, '-');\r\n return id;\r\n}\r\n\r\nexport function getComponentSourceByCaller(depth = 2): string | null {\r\n const err = new Error();\r\n const stack = err.stack?.split('\\n');\r\n if (!stack || stack.length <= depth) {\r\n return null;\r\n }\r\n const match = stack[depth].match(/\\(([^)]+)\\)/);\r\n const result = match?.[1];\r\n if (result) {\r\n if (\r\n document.querySelector('script[type=\"module\"][src*=\"/@vite/\"]') &&\r\n globalThis['CONFIG_TYPE'] === 'DEVELOPMENT'\r\n ) {\r\n return result.replace(/\\?[^:]+/, '');\r\n }\r\n }\r\n return result;\r\n}\r\n\r\nexport function getComponentNameByCaller(depth = 2): string | null {\r\n const err = new Error();\r\n const stack = err.stack?.split('\\n');\r\n if (!stack || stack.length <= depth) {\r\n return null;\r\n }\r\n const line = stack[depth].trim();\r\n const match = line.match(/^at\\s+([^\\s(]+)/);\r\n if (!match) {\r\n return null;\r\n }\r\n const fnName = match[1];\r\n const hookMatch = fnName.match(/^use(.+)/);\r\n if (hookMatch) {\r\n return hookMatch[1];\r\n }\r\n return fnName;\r\n}\r\n\r\nexport function registerMsgBroker<TStruct extends ComponentStruct = ComponentStruct>(\r\n component: Component<TStruct>,\r\n) {\r\n const providers = component?.msgBroker.provide;\r\n if (providers) {\r\n for (const [channel, providerGroups] of Object.entries(providers)) {\r\n for (const [g, p] of Object.entries(providerGroups)) {\r\n const provider = p as MsgChannelGroupProviderParams;\r\n const callback = provider.callback;\r\n if (callback) {\r\n provider.callback = (msg, headers) => {\r\n return callback(msg, headers, component);\r\n };\r\n }\r\n const filter = provider.filter;\r\n const componentFilter = provider.componentFilter || ComponentMsgFilter.None;\r\n const msgFilter = (msg) => {\r\n let result = true;\r\n if (componentFilter & ComponentMsgFilter.FromAncestors) {\r\n const ancestorIds = component.getChainUp();\r\n result = ancestorIds.indexOf(msg.headers?.sourceId) >= 0;\r\n }\r\n if (result && componentFilter & ComponentMsgFilter.FromDescendants) {\r\n const ancestorIds = component.getChainDown();\r\n result = ancestorIds.indexOf(msg.headers?.sourceId) >= 0;\r\n }\r\n if (result && filter) {\r\n result = filter(msg, component);\r\n }\r\n return result;\r\n };\r\n provider.filter = msgFilter;\r\n\r\n component.msgBus.provide({\r\n ...p,\r\n channel: channel,\r\n group: g,\r\n options: {\r\n abortSignal: component.msgBroker.abortController.signal,\r\n },\r\n });\r\n }\r\n }\r\n }\r\n const subscribers = component?.msgBroker?.subscribe;\r\n if (subscribers) {\r\n for (const [channel, subscriberGroups] of Object.entries(subscribers)) {\r\n for (const [g, s] of Object.entries(subscriberGroups)) {\r\n const subscriber = s as MsgChannelGroupSubscriberParams;\r\n const callback = subscriber.callback;\r\n if (callback) {\r\n subscriber.callback = (msg) => {\r\n return callback(msg, component);\r\n };\r\n }\r\n const filter = subscriber.filter;\r\n const componentFilter = subscriber.componentFilter || ComponentMsgFilter.None;\r\n const msgFilter = (msg) => {\r\n let result = true;\r\n if (componentFilter & ComponentMsgFilter.FromAncestors) {\r\n const ancestorIds = component.getChainUp();\r\n result = ancestorIds.indexOf(msg.headers?.sourceId) >= 0;\r\n }\r\n if (result && componentFilter & ComponentMsgFilter.FromDescendants) {\r\n const ancestorIds = component.getChainDown();\r\n result = ancestorIds.indexOf(msg.headers?.sourceId) >= 0;\r\n }\r\n if (result && filter) {\r\n result = filter(msg, component);\r\n }\r\n return result;\r\n };\r\n subscriber.filter = msgFilter;\r\n\r\n component.msgBus.on({\r\n ...s,\r\n channel: channel,\r\n group: g,\r\n config: {\r\n abortSignal: component.msgBroker.abortController.signal,\r\n },\r\n });\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport function getComponentMsgBus<TStruct extends ComponentStruct = ComponentStruct>(\r\n msgBus: MsgBus<TStruct['msg']>,\r\n headerSetter: (headers?: ComponentMsgHeaders) => void,\r\n) {\r\n const updateParams = (params: { payload?: any; headers?: ComponentMsgHeaders }) => {\r\n if (params.payload != undefined) {\r\n params.payload = structuredClone(toJS(params.payload)); // always?\r\n }\r\n if (!params.headers) {\r\n params.headers = {};\r\n }\r\n headerSetter?.(params.headers);\r\n };\r\n return {\r\n config: msgBus.config,\r\n on: (params) => {\r\n return msgBus.on(params);\r\n },\r\n once: (params) => {\r\n return msgBus.once(params);\r\n },\r\n stream: (params) => {\r\n return msgBus.stream(params);\r\n },\r\n provide: (params) => {\r\n updateParams(params);\r\n return msgBus.provide(params);\r\n },\r\n send: (params) => {\r\n updateParams(params);\r\n return msgBus.send(params);\r\n },\r\n request: (params) => {\r\n updateParams(params);\r\n return msgBus.request(params);\r\n },\r\n } as MsgBus<TStruct['msg']>;\r\n}\r\n\r\nexport function createEffect<\r\n TStruct extends ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n>(\r\n component: Component<TStruct, TMsgHeaders>,\r\n name: string,\r\n fn: EffectFn<TStruct, TMsgHeaders>,\r\n): EffectController {\r\n let disposer: IReactionDisposer | null = null;\r\n let paused = false;\r\n let effectCleanup: () => void = undefined;\r\n\r\n const start = () => {\r\n if (disposer) {\r\n return;\r\n }\r\n\r\n disposer = autorun(\r\n () => {\r\n if (!paused) {\r\n const cleanup = fn(component);\r\n if (typeof cleanup === 'function') {\r\n cleanup();\r\n effectCleanup = cleanup;\r\n }\r\n }\r\n },\r\n { name: `effect:${name}` },\r\n );\r\n };\r\n\r\n const stop = () => {\r\n disposer?.();\r\n disposer = null;\r\n if (effectCleanup) {\r\n effectCleanup();\r\n effectCleanup = undefined;\r\n }\r\n };\r\n\r\n const pause = () => {\r\n paused = true;\r\n };\r\n\r\n const resume = () => {\r\n paused = false;\r\n };\r\n\r\n const restart = () => {\r\n stop();\r\n start();\r\n };\r\n\r\n start();\r\n\r\n return { start, pause, resume, stop, restart };\r\n}\r\n\r\n// TODO: move to utico\r\n// function asyncToGeneratorFlow(asyncFn: (...args: any[]) => Promise<any>) {\r\n// return function* (...args: any[]) {\r\n// const result = yield asyncFn(...args);\r\n// return result;\r\n// };\r\n// }\r\n"],"names":["isBinding","obj","$isBinding","bind","get","set","converter","validator","bindProp","target","prop","value","proxyCache","createRecursiveProxy","bindings","handlers","isObservable","proxy","receiver","onGet","binding","oldValue","onChanging","result","runInAction","toHtmlId","url","segment","getComponentSourceByCaller","depth","stack","getComponentNameByCaller","match","fnName","hookMatch","registerMsgBroker","component","providers","channel","providerGroups","g","p","provider","callback","msg","headers","filter","componentFilter","ComponentMsgFilter","msgFilter","subscribers","subscriberGroups","subscriber","getComponentMsgBus","msgBus","headerSetter","updateParams","params","toJS","createEffect","name","fn","disposer","paused","effectCleanup","start","autorun","cleanup","stop","pause","resume","restart"],"mappings":";;AAuBO,SAASA,EAAUC,GAA0B;AAChD,SAAOA,EAAIC,CAAU,MAAM;AAC/B;AAEO,SAASC,EACZC,GACAC,GACAC,GACAC,GACO;AACP,SAAO;AAAA,IACH,KAAAH;AAAA,IACA,KAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,UAAU,CAAC,CAACF;AAAA,IACZ,CAACH,CAAU,GAAG;AAAA,EAAA;AAEtB;AAEO,SAASM,EAA8CC,GAAiBC,GAAkB;AAC7F,SAAO;AAAA,IACH,KAAK,MAAMD,EAAA,EAASC,CAAI;AAAA,IACxB,KAAK,CAACC,MAAgB;AAClB,MAAAF,EAAA,EAASC,CAAI,IAAIC;AAAA,IACrB;AAAA,IACA,CAACT,CAAU,GAAG;AAAA,EAAA;AAEtB;AAEA,MAAMU,wBAAiB,QAAA;AAOhB,SAASC,EACZJ,GACAK,GACAC,GACF;AAME,MALI,OAAON,KAAW,YAAYA,MAAW,QAKzC,CAACO,EAAaP,CAAM;AACpB,WAAOA;AAGX,MAAIG,EAAW,IAAIH,CAAM;AACrB,WAAOG,EAAW,IAAIH,CAAM;AAGhC,QAAMQ,IAAQ,IAAI,MAAMR,GAAQ;AAAA,IAC5B,IAAIR,GAAKS,G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
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { Component, ComponentDef, ComponentMsgHeaders, ComponentParams, ComponentStruct } from './contracts';
3
+ export declare function useComponent<TStruct extends ComponentStruct = ComponentStruct, TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders>(componentDef: ComponentDef<TStruct, TMsgHeaders>, params: ComponentParams<TStruct>): any;
4
+ export declare function getFC<TStruct extends ComponentStruct>(factory: (params: ComponentParams<TStruct>) => Component<TStruct>): FC<ComponentParams<TStruct>>;
5
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/componentModel/react.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAiD,EAAE,EAAW,MAAM,OAAO,CAAC;AAO1F,OAAO,EAIH,SAAS,EAET,YAAY,EAEZ,mBAAmB,EACnB,eAAe,EACf,eAAe,EAOlB,MAAM,aAAa,CAAC;AAkXrB,wBAAgB,YAAY,CACxB,OAAO,SAAS,eAAe,GAAG,eAAe,EACjD,WAAW,SAAS,mBAAmB,GAAG,mBAAmB,EAC/D,YAAY,EAAE,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,OAQnF;AAGD,wBAAgB,KAAK,CAAC,OAAO,SAAS,eAAe,EACjD,OAAO,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC,OAAO,CAAC,GAClE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAS9B"}
@@ -0,0 +1,201 @@
1
+ import h, { useLayoutEffect as R, useEffect as z, useMemo as U } from "react";
2
+ import { observer as A } from "mobx-react-lite";
3
+ import { observable as w } from "mobx";
4
+ import { useLazyRef as _ } from "../reactHooks.es.js";
5
+ import { getGlobalFlags as C } from "../globals.es.js";
6
+ import { useComponentContext as p, ReactComponentContext as J } from "./componentContext.es.js";
7
+ import { $id as B, $key as M, $ON_CHANGE as V, $ON_CHANGING as q, $ON_GET as K } from "./contracts.es.js";
8
+ import { lazy as Q } from "@actdim/utico/utils";
9
+ import { getComponentSourceByCaller as W, getComponentMsgBus as X, toHtmlId as Y, registerMsgBroker as Z, isBinding as m, createRecursiveProxy as D, createEffect as ee } from "./core.es.js";
10
+ function b(e) {
11
+ return e.replace(/^./, e[0].toUpperCase());
12
+ }
13
+ function te(e) {
14
+ return e.replace(/^[a-z][a-z0-9+.-]*:\/\/[^\/]+/, "");
15
+ }
16
+ function re(e, o) {
17
+ let t, c;
18
+ e || (e = {});
19
+ let a = e.regType;
20
+ a || (a = W(6), a = te(a)), o || (o = {});
21
+ const k = e.view;
22
+ let I = e.msgBus;
23
+ const E = /* @__PURE__ */ new Map(), j = Q(() => X(I, (n) => {
24
+ n?.sourceId == null && (n.sourceId = t.id);
25
+ }));
26
+ let f = {
27
+ ...e.msgBroker
28
+ };
29
+ f.abortController || (f.abortController = new AbortController());
30
+ const S = A((n) => {
31
+ const r = p(), s = r.currentId;
32
+ t.parentId = s, I || (I = r.msgBus);
33
+ const d = r.getNodeMap(), l = ((i) => r.getChildren(i).map((N) => d.get(N)))(s);
34
+ let u = o[B];
35
+ if (!u) {
36
+ let i = Y(a), y = o[M];
37
+ y || (y = (l.filter(
38
+ (T) => T.regType === e.regType
39
+ ).length + 1).toString()), u = `${i}#${y}`;
40
+ }
41
+ t.id = u, t.getHierarchyId = () => r.getHierarchyPath(u), t.getChainDown = () => r.getChainDown(u), t.getChainUp = () => r.getChainUp(u), t.getChildren = () => r.getChildren(u), t.getParent = () => r.getParent(u), t.getNodeMap = () => r.getNodeMap(), R(() => {
42
+ try {
43
+ if (r.register(u, e.regType, s), C().debug) {
44
+ const i = t.getHierarchyId();
45
+ console.debug(`${i}>layout`);
46
+ }
47
+ Z(t), e.events?.onLayout?.(t), o.onLayout?.(t);
48
+ } catch (i) {
49
+ e.events?.onError?.(t, i), o.onError?.(t, i);
50
+ }
51
+ return () => {
52
+ if (C().debug) {
53
+ const i = t.getHierarchyId();
54
+ console.debug(`${i}>layout-destroy`);
55
+ }
56
+ r.unregister(t.id), f.abortController?.abort(), e.events?.onLayoutDestroy?.(t), o.onLayoutDestroy?.(t);
57
+ };
58
+ }, [e, o, r]), z(() => {
59
+ try {
60
+ if (C().debug) {
61
+ const i = t.getHierarchyId();
62
+ console.debug(`${i}>ready`);
63
+ }
64
+ e.events?.onReady?.(t), o.onReady?.(t);
65
+ } catch (i) {
66
+ if (C().debug) {
67
+ const y = t.getHierarchyId();
68
+ console.debug(`${y}>destroy`);
69
+ }
70
+ e.events?.onError?.(t, i), o.onError?.(t, i);
71
+ }
72
+ return () => {
73
+ e.events?.onDestroy?.(t), o.onDestroy?.(t);
74
+ };
75
+ }, [e, o, r]);
76
+ let v;
77
+ try {
78
+ if (C().debug) {
79
+ const i = t.getHierarchyId();
80
+ console.debug(`${i}>view`);
81
+ }
82
+ typeof k == "function" ? v = k(n, t) : v = /* @__PURE__ */ h.createElement(h.Fragment, null, n.children);
83
+ } catch (i) {
84
+ const y = JSON.stringify(i);
85
+ v = /* @__PURE__ */ h.createElement(h.Fragment, null, y);
86
+ }
87
+ const L = U(
88
+ () => ({ ...r, currentId: t.id }),
89
+ [e, o, r]
90
+ );
91
+ return /* @__PURE__ */ h.createElement(J.Provider, { value: L }, v);
92
+ }), $ = {};
93
+ if (c = {}, e.props && Object.assign(c, e.props), e.actions && Object.assign(c, e.actions), e.children)
94
+ for (const [n, r] of Object.entries(e.children))
95
+ if (typeof r == "function") {
96
+ const s = r, d = (g) => {
97
+ const l = s(g);
98
+ return /* @__PURE__ */ h.createElement(l.View, null);
99
+ };
100
+ Reflect.set($, b(n), d);
101
+ } else
102
+ Reflect.set($, n, r);
103
+ for (const [n, r] of Object.entries(o))
104
+ n in c && (m(r) ? E.set(n, r) : Reflect.set(c, n, r));
105
+ const P = {
106
+ onPropChanging: o.onPropChanging || e.events?.onPropChanging ? (n, r, s) => {
107
+ let d = !0, g = o.onPropChanging;
108
+ return g && (d = g(String(n), r, s)), d && (g = e.events?.onPropChanging, g && (d = g(String(n), r, s))), d;
109
+ } : void 0,
110
+ onPropChange: o.onPropChange || e.events?.onPropChange ? (n, r) => {
111
+ o.onPropChange?.(String(n), r), e.events?.onPropChange?.(String(n), r);
112
+ } : void 0
113
+ };
114
+ function x(n) {
115
+ const r = `${K}${b(n)}`;
116
+ return o[r] || e.events?.[r];
117
+ }
118
+ function G(n) {
119
+ const r = `${q}${b(n)}`;
120
+ return ((s, d) => {
121
+ let g = !0, l = o[r];
122
+ return l && (g = l(s, d)), g && (l = e.events?.[r], l && (g = l(s, d))), g;
123
+ });
124
+ }
125
+ function F(n) {
126
+ const r = `${V}${b(n)}`;
127
+ return ((s) => {
128
+ o[r]?.(s), e.events?.[r]?.(s);
129
+ });
130
+ }
131
+ let H = {};
132
+ if (e.props) {
133
+ for (const n of Object.keys(e.props))
134
+ P[n] = {
135
+ onGet: x(n),
136
+ onChanging: G(n),
137
+ onChange: F(n)
138
+ };
139
+ for (const n of Object.keys(e.props))
140
+ H[n] = w.deep;
141
+ }
142
+ if (e.actions)
143
+ for (const n of Object.keys(e.actions))
144
+ ;
145
+ c = w(c, H, {
146
+ deep: !0
147
+ }), c = D(c, E, P);
148
+ let O = {};
149
+ if (t = {
150
+ id: o[B],
151
+ key: o[M],
152
+ regType: a,
153
+ parentId: void 0,
154
+ getHierarchyId: () => {
155
+ },
156
+ getChainDown: () => {
157
+ },
158
+ getChainUp: () => {
159
+ },
160
+ getChildren: () => {
161
+ },
162
+ getParent: () => {
163
+ },
164
+ getNodeMap: () => {
165
+ },
166
+ bindings: E,
167
+ get msgBus() {
168
+ return j();
169
+ },
170
+ msgBroker: f,
171
+ effects: O,
172
+ // view: componentDef.view,
173
+ View: S,
174
+ children: $,
175
+ model: c
176
+ }, e.effects)
177
+ for (const [n, r] of Object.entries(e.effects))
178
+ O[n] = ee(
179
+ t,
180
+ n,
181
+ r
182
+ );
183
+ return e.events?.onInit && e.events.onInit(t), o.onInit && o.onInit(t), t;
184
+ }
185
+ function ye(e, o) {
186
+ const t = _(() => re(e, o));
187
+ return R(() => () => {
188
+ t.current = null;
189
+ }, [e, o]), t.current;
190
+ }
191
+ function he(e) {
192
+ return (t) => {
193
+ const c = e(t);
194
+ return /* @__PURE__ */ h.createElement(c.View, { ...t });
195
+ };
196
+ }
197
+ export {
198
+ he as getFC,
199
+ ye as useComponent
200
+ };
201
+ //# sourceMappingURL=react.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.es.js","sources":["../../src/componentModel/react.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useLayoutEffect, FC, useMemo } from 'react';\r\nimport { Mutable } from '@actdim/utico/typeCore';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { action, observable } from 'mobx';\r\nimport { useLazyRef } from '@/reactHooks';\r\nimport { getGlobalFlags } from '@/globals';\r\nimport { ReactComponentContext, useComponentContext } from './componentContext';\r\nimport {\r\n $id,\r\n $key,\r\n Binding,\r\n Component,\r\n ComponentChildren,\r\n ComponentDef,\r\n ComponentModel,\r\n ComponentMsgHeaders,\r\n ComponentParams,\r\n ComponentStruct,\r\n ComponentViewImplFn,\r\n ComponentViewProps,\r\n EffectController,\r\n EffectFn,\r\n ValueChangeHandler,\r\n ValueChangingHandler,\r\n} from './contracts';\r\nimport { $ON_CHANGE, $ON_CHANGING, $ON_GET, $isBinding, ComponentMsgFilter } from './contracts';\r\nimport { lazy } from '@actdim/utico/utils';\r\nimport {\r\n createEffect,\r\n createRecursiveProxy,\r\n getComponentSourceByCaller,\r\n getComponentMsgBus,\r\n isBinding,\r\n ProxyEventHandlers,\r\n registerMsgBroker,\r\n toHtmlId,\r\n} from './core';\r\n\r\nfunction capitalize(name: string) {\r\n return name.replace(/^./, name[0].toUpperCase());\r\n}\r\n\r\nfunction cleanSourceRef(sourceRef: string) {\r\n // remove origin\r\n return sourceRef.replace(/^[a-z][a-z0-9+.-]*:\\/\\/[^\\/]+/, '');\r\n}\r\n\r\nfunction createComponent<TStruct extends ComponentStruct = ComponentStruct>(\r\n componentDef: ComponentDef<TStruct>,\r\n params?: ComponentParams<TStruct>,\r\n): Component<TStruct> {\r\n // result\r\n let component: Mutable<Component<TStruct>>;\r\n let model: Mutable<ComponentModel<TStruct>>;\r\n\r\n if (!componentDef) {\r\n componentDef = {};\r\n }\r\n\r\n let type = componentDef.regType;\r\n if (!type) {\r\n type = getComponentSourceByCaller(6);\r\n // type = getComponentNameByCaller(6);\r\n type = cleanSourceRef(type);\r\n // throw new Error('Valid component definition is required');\r\n }\r\n\r\n if (!params) {\r\n params = {};\r\n }\r\n\r\n const view = componentDef.view;\r\n let msgBus = componentDef.msgBus;\r\n\r\n const bindings = new Map<PropertyKey, Binding>();\r\n\r\n const componentMsgBus = lazy(() => {\r\n return getComponentMsgBus(msgBus, (headers) => {\r\n if (headers?.sourceId == undefined) {\r\n headers.sourceId = component.id;\r\n }\r\n }); // as ComponentModel<TStruct>['msgBus']\r\n });\r\n\r\n let msgBroker = {\r\n ...componentDef.msgBroker,\r\n };\r\n\r\n if (!msgBroker.abortController) {\r\n msgBroker.abortController = new AbortController();\r\n }\r\n\r\n const ViewFC = observer((props: ComponentViewProps) => {\r\n const context = useComponentContext();\r\n const parentId = context.currentId;\r\n\r\n component.parentId = parentId;\r\n\r\n if (!msgBus) {\r\n msgBus = context.msgBus;\r\n }\r\n\r\n const nodeMap = context.getNodeMap();\r\n\r\n const getChildNodes = (id: string) => {\r\n const childIds = context.getChildren(id);\r\n return childIds.map((childId) => nodeMap.get(childId));\r\n };\r\n\r\n const childNodes = getChildNodes(parentId);\r\n let id = params[$id];\r\n if (!id) {\r\n let name = toHtmlId(type);\r\n let key = params[$key];\r\n if (!key) {\r\n const componentCount = childNodes.filter(\r\n (node) => node.regType === componentDef.regType,\r\n ).length;\r\n key = (componentCount + 1).toString();\r\n }\r\n id = `${name}#${key}`;\r\n }\r\n\r\n component.id = id;\r\n component.getHierarchyId = () => context.getHierarchyPath(id);\r\n component.getChainDown = () => context.getChainDown(id);\r\n component.getChainUp = () => context.getChainUp(id);\r\n component.getChildren = () => context.getChildren(id);\r\n component.getParent = () => context.getParent(id);\r\n component.getNodeMap = () => context.getNodeMap();\r\n\r\n useLayoutEffect(() => {\r\n try {\r\n context.register(id, componentDef.regType, parentId);\r\n\r\n if (getGlobalFlags().debug) {\r\n const hierarchyId = component.getHierarchyId();\r\n console.debug(`${hierarchyId}>layout`);\r\n }\r\n\r\n registerMsgBroker(component);\r\n\r\n componentDef.events?.onLayout?.(component);\r\n params.onLayout?.(component);\r\n } catch (err) {\r\n componentDef.events?.onError?.(component, err);\r\n params.onError?.(component, err);\r\n }\r\n\r\n return () => {\r\n if (getGlobalFlags().debug) {\r\n const hierarchyId = component.getHierarchyId();\r\n console.debug(`${hierarchyId}>layout-destroy`);\r\n }\r\n context.unregister(component.id);\r\n\r\n msgBroker.abortController?.abort();\r\n\r\n componentDef.events?.onLayoutDestroy?.(component);\r\n params.onLayoutDestroy?.(component);\r\n };\r\n }, [componentDef, params, context]);\r\n\r\n useEffect(() => {\r\n try {\r\n if (getGlobalFlags().debug) {\r\n // mount\r\n const hierarchyId = component.getHierarchyId();\r\n console.debug(`${hierarchyId}>ready`);\r\n }\r\n componentDef.events?.onReady?.(component);\r\n params.onReady?.(component);\r\n } catch (err) {\r\n if (getGlobalFlags().debug) {\r\n // unmount\r\n const hierarchyId = component.getHierarchyId();\r\n console.debug(`${hierarchyId}>destroy`);\r\n }\r\n componentDef.events?.onError?.(component, err);\r\n params.onError?.(component, err);\r\n }\r\n return () => {\r\n componentDef.events?.onDestroy?.(component);\r\n params.onDestroy?.(component);\r\n };\r\n }, [componentDef, params, context]);\r\n\r\n let content: React.ReactNode;\r\n // let content: any;\r\n try {\r\n if (getGlobalFlags().debug) {\r\n // render\r\n const hierarchyId = component.getHierarchyId();\r\n console.debug(`${hierarchyId}>view`);\r\n }\r\n if (typeof view === 'function') {\r\n content = view(props, component);\r\n } else {\r\n // content = props.children;\r\n content = <>{props.children}</>;\r\n }\r\n } catch (err) {\r\n // throw err;\r\n const errDetails = JSON.stringify(err);\r\n // msgBus.send\r\n content = <>{errDetails}</>;\r\n }\r\n const scopeContext = useMemo(\r\n () => ({ ...context, currentId: component.id }),\r\n [componentDef, params, context],\r\n );\r\n return (\r\n <ReactComponentContext.Provider value={scopeContext}>\r\n {content}\r\n </ReactComponentContext.Provider>\r\n );\r\n });\r\n\r\n const children = {} as ComponentChildren<TStruct['children']>;\r\n\r\n model = {} as Mutable<ComponentModel<TStruct>>;\r\n\r\n if (componentDef.props) {\r\n Object.assign(model, componentDef.props);\r\n }\r\n\r\n if (componentDef.actions) {\r\n Object.assign(model, componentDef.actions);\r\n }\r\n\r\n if (componentDef.children) {\r\n for (const [key, value] of Object.entries(componentDef.children)) {\r\n if (typeof value == 'function') {\r\n const view = value as (params: any) => Component;\r\n // observer\r\n const ChildViewFC: ComponentViewImplFn<TStruct> = (props) => {\r\n const c = view(props);\r\n return <c.View />;\r\n // if (typeof c.view === \"function\") {\r\n // return c.view(props);\r\n // }\r\n // return <>{props.children}</>;\r\n };\r\n Reflect.set(children, capitalize(key), ChildViewFC);\r\n } else {\r\n Reflect.set(children, key, value);\r\n }\r\n }\r\n }\r\n\r\n // Reflect.ownKeys/Object.keys\r\n for (const [key, value] of Object.entries(params)) {\r\n // model.hasOwnProperty(key)\r\n if (key in model) {\r\n if (isBinding(value)) {\r\n bindings.set(key, value);\r\n } else {\r\n Reflect.set(model, key, value);\r\n }\r\n }\r\n }\r\n\r\n const proxyEventHandlers: Pick<ProxyEventHandlers, 'onPropChanging' | 'onPropChange'> = {\r\n onPropChanging:\r\n params.onPropChanging || componentDef.events?.onPropChanging\r\n ? (prop, oldValue, newValue) => {\r\n let result = true;\r\n let handler = params.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = componentDef.events?.onPropChanging;\r\n if (handler) {\r\n result = handler(String(prop), oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }\r\n : undefined,\r\n onPropChange:\r\n params.onPropChange || componentDef.events?.onPropChange\r\n ? (prop, value) => {\r\n params.onPropChange?.(String(prop), value);\r\n componentDef.events?.onPropChange?.(String(prop), value);\r\n }\r\n : undefined,\r\n };\r\n\r\n function resolveOnGetEventHandler(prop: string) {\r\n const key = `${$ON_GET}${capitalize(prop)}`;\r\n return params[key] || componentDef.events?.[key];\r\n }\r\n\r\n function resolveOnChangingEventHandler(prop: string) {\r\n const key = `${$ON_CHANGING}${capitalize(prop)}`;\r\n return ((oldValue: any, newValue: any) => {\r\n let result = true;\r\n let handler = params[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n if (result) {\r\n handler = componentDef.events?.[key] as ValueChangingHandler<any>;\r\n if (handler) {\r\n result = handler(oldValue, newValue);\r\n }\r\n }\r\n return result;\r\n }) as ValueChangingHandler;\r\n }\r\n\r\n function resolveOnChangeEventHandler(prop: string) {\r\n const key = `${$ON_CHANGE}${capitalize(prop)}`;\r\n return ((value: any) => {\r\n (params[key] as ValueChangeHandler<any>)?.(value);\r\n (componentDef.events?.[key] as ValueChangeHandler<any>)?.(value);\r\n }) as ValueChangeHandler;\r\n }\r\n\r\n let annotationMap: Record<string, any> = {};\r\n\r\n if (componentDef.props) {\r\n for (const prop of Object.keys(componentDef.props)) {\r\n proxyEventHandlers[prop] = {\r\n onGet: resolveOnGetEventHandler(prop),\r\n onChanging: resolveOnChangingEventHandler(prop),\r\n onChange: resolveOnChangeEventHandler(prop),\r\n };\r\n }\r\n\r\n for (const key of Object.keys(componentDef.props)) {\r\n annotationMap[key] = observable.deep;\r\n }\r\n }\r\n\r\n if (componentDef.actions) {\r\n const annotationMap: Record<string, any> = {};\r\n for (const key of Object.keys(componentDef.actions)) {\r\n annotationMap[key] = action;\r\n }\r\n }\r\n\r\n model = observable(model, annotationMap, {\r\n deep: true,\r\n });\r\n\r\n model = createRecursiveProxy(model, bindings, proxyEventHandlers);\r\n\r\n let effects: Record<string, EffectController> = {};\r\n component = {\r\n id: params[$id],\r\n key: params[$key],\r\n regType: type,\r\n parentId: undefined,\r\n getHierarchyId: () => undefined,\r\n getChainDown: () => undefined,\r\n getChainUp: () => undefined,\r\n getChildren: () => undefined,\r\n getParent: () => undefined,\r\n getNodeMap: () => undefined,\r\n bindings: bindings,\r\n get msgBus() {\r\n return componentMsgBus();\r\n },\r\n msgBroker: msgBroker,\r\n effects: effects,\r\n // view: componentDef.view,\r\n View: ViewFC,\r\n children: children,\r\n model: model,\r\n };\r\n\r\n if (componentDef.effects) {\r\n for (const [name, fn] of Object.entries(componentDef.effects)) {\r\n effects[name] = createEffect(\r\n component,\r\n name,\r\n fn as EffectFn<TStruct, ComponentMsgHeaders>,\r\n );\r\n }\r\n }\r\n\r\n if (componentDef.events?.onInit) {\r\n componentDef.events.onInit(component);\r\n }\r\n\r\n if (params.onInit) {\r\n params.onInit(component);\r\n }\r\n\r\n return component;\r\n}\r\n\r\nexport function useComponent<\r\n TStruct extends ComponentStruct = ComponentStruct,\r\n TMsgHeaders extends ComponentMsgHeaders = ComponentMsgHeaders,\r\n>(componentDef: ComponentDef<TStruct, TMsgHeaders>, params: ComponentParams<TStruct>) {\r\n const ref = useLazyRef(() => createComponent(componentDef, params));\r\n useLayoutEffect(() => {\r\n return () => {\r\n ref.current = null;\r\n };\r\n }, [componentDef, params]);\r\n return ref.current;\r\n}\r\n\r\n// asFC/toFC\r\nexport function getFC<TStruct extends ComponentStruct>(\r\n factory: (params: ComponentParams<TStruct>) => Component<TStruct>,\r\n): FC<ComponentParams<TStruct>> {\r\n // observer\r\n const fc = (params: ComponentParams<TStruct> & PropsWithChildren) => {\r\n // componentHook\r\n const c = factory(params); // without useRef!\r\n // return c.view();\r\n return <c.View {...params} />;\r\n };\r\n return fc;\r\n}\r\n"],"names":["capitalize","name","cleanSourceRef","sourceRef","createComponent","componentDef","params","component","model","type","getComponentSourceByCaller","view","msgBus","bindings","componentMsgBus","lazy","getComponentMsgBus","headers","msgBroker","ViewFC","observer","props","context","useComponentContext","parentId","nodeMap","childNodes","id","childId","$id","toHtmlId","key","$key","node","useLayoutEffect","getGlobalFlags","hierarchyId","registerMsgBroker","err","useEffect","content","React","errDetails","scopeContext","useMemo","ReactComponentContext","children","value","ChildViewFC","c","isBinding","proxyEventHandlers","prop","oldValue","newValue","result","handler","resolveOnGetEventHandler","$ON_GET","resolveOnChangingEventHandler","$ON_CHANGING","resolveOnChangeEventHandler","$ON_CHANGE","annotationMap","observable","createRecursiveProxy","effects","fn","createEffect","useComponent","ref","useLazyRef","getFC","factory"],"mappings":";;;;;;;;;AAsCA,SAASA,EAAWC,GAAc;AAC9B,SAAOA,EAAK,QAAQ,MAAMA,EAAK,CAAC,EAAE,aAAa;AACnD;AAEA,SAASC,GAAeC,GAAmB;AAEvC,SAAOA,EAAU,QAAQ,iCAAiC,EAAE;AAChE;AAEA,SAASC,GACLC,GACAC,GACkB;AAElB,MAAIC,GACAC;AAEJ,EAAKH,MACDA,IAAe,CAAA;AAGnB,MAAII,IAAOJ,EAAa;AACxB,EAAKI,MACDA,IAAOC,EAA2B,CAAC,GAEnCD,IAAOP,GAAeO,CAAI,IAIzBH,MACDA,IAAS,CAAA;AAGb,QAAMK,IAAON,EAAa;AAC1B,MAAIO,IAASP,EAAa;AAE1B,QAAMQ,wBAAe,IAAA,GAEfC,IAAkBC,EAAK,MAClBC,EAAmBJ,GAAQ,CAACK,MAAY;AAC3C,IAAIA,GAAS,YAAY,SACrBA,EAAQ,WAAWV,EAAU;AAAA,EAErC,CAAC,CACJ;AAED,MAAIW,IAAY;AAAA,IACZ,GAAGb,EAAa;AAAA,EAAA;AAGpB,EAAKa,EAAU,oBACXA,EAAU,kBAAkB,IAAI,gBAAA;AAGpC,QAAMC,IAASC,EAAS,CAACC,MAA8B;AACnD,UAAMC,IAAUC,EAAA,GACVC,IAAWF,EAAQ;AAEzB,IAAAf,EAAU,WA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AAkDC,GAAkC;AAClF,QAAMgE,IAAMC,EAAW,MAAMnE,GAAgBC,GAAcC,CAAM,CAAC;AAClE,SAAA4B,EAAgB,MACL,MAAM;AACT,IAAAoC,EAAI,UAAU;AAAA,EAClB,GACD,CAACjE,GAAcC,CAAM,CAAC,GAClBgE,EAAI;AACf;AAGO,SAASE,GACZC,GAC4B;AAQ5B,SANW,CAACnE,MAAyD;AAEjE,UAAM,IAAImE,EAAQnE,CAAM;AAExB,WAAO,gBAAAmC,EAAA,cAAC,EAAE,MAAF,EAAQ,GAAGnC,GAAQ;AAAA,EAC/B;AAEJ;"}
@@ -9,7 +9,8 @@ export declare class ClientBase {
9
9
  private msgBus;
10
10
  private accessToken;
11
11
  private init;
12
- constructor(context: BaseAppContext, fetcher?: IFetcher);
12
+ private apiSuffixes;
13
+ constructor(context: BaseAppContext, fetcher?: IFetcher, apiSuffixes?: string[]);
13
14
  protected getBaseUrlAsync(): Promise<void>;
14
15
  private updateSecurityAsync;
15
16
  private addAuthorizationAsync;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/net/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,QAAQ,EAAqB,cAAc,EAAiB,MAAM,WAAW,CAAC;AAE1G,OAAO,EAAoB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAS5E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAY9E;AAID,qBAAa,UAAU;IACnB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,eAAe,CAA6B;IAEpD,OAAO,CAAC,OAAO,CAAW;IAE1B,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,IAAI,CAAe;gBAEf,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,QAAQ;cAevC,eAAe;YAUjB,mBAAmB;YAUnB,qBAAqB;YAqBrB,2BAA2B;YAkD3B,mBAAmB;IA+CpB,UAAU,CAAC,CAAC,EAAE,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;CA2CxE"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/net/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,QAAQ,EAAqB,cAAc,EAAiB,MAAM,WAAW,CAAC;AAE1G,OAAO,EAAoB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAS5E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAa9E;AAID,qBAAa,UAAU;IACnB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAE1B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IAGvB,OAAO,CAAC,eAAe,CAA6B;IAEpD,OAAO,CAAC,OAAO,CAAW;IAE1B,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,IAAI,CAAe;IAE3B,OAAO,CAAC,WAAW,CAAW;gBAElB,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,WAAW,WAAe;cAgBnE,eAAe;YAcjB,mBAAmB;YAUnB,qBAAqB;YAqBrB,2BAA2B;YAkD3B,mBAAmB;IA+CpB,UAAU,CAAC,CAAC,EAAE,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;CA2CxE"}
@@ -1,16 +1,16 @@
1
1
  import { v4 as d } from "uuid";
2
2
  import o from "http-status";
3
- import { getResponseResult as p } from "./request.es.js";
3
+ import { getResponseResult as u } from "./request.es.js";
4
4
  import { ApiError as r } from "./apiError.es.js";
5
- function u(c, e) {
6
- if (!c)
7
- return c;
8
- const t = e.map((i) => i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), a = new RegExp(`(_?(${t}))+?$`, "i");
9
- let n = c.replace(a, "");
10
- return n = n.trim(), n.length > 0 ? n : c;
5
+ function f(i, e) {
6
+ if (!i)
7
+ return i;
8
+ const t = e.map((c) => c.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), s = new RegExp(`(_?(${t}))+?$`, "i");
9
+ let a = i.replace(s, "");
10
+ return a = a.trim(), a.length > 0 ? a : i;
11
11
  }
12
- const f = ["api", "controller", "client", "fetcher"];
13
- class R {
12
+ const p = ["api", "controller", "client", "fetcher"];
13
+ class g {
14
14
  baseUrl;
15
15
  name;
16
16
  // private requestStates
@@ -19,24 +19,25 @@ class R {
19
19
  msgBus;
20
20
  accessToken;
21
21
  init;
22
- constructor(e, s) {
23
- this.fetcher = s || window, this.requestStateMap = /* @__PURE__ */ new Map(), this.msgBus = e.msgBus, this.msgBus.on({
22
+ apiSuffixes;
23
+ constructor(e, n, t = p) {
24
+ this.apiSuffixes = t, this.fetcher = n || window, this.requestStateMap = /* @__PURE__ */ new Map(), this.msgBus = e.msgBus, this.msgBus.on({
24
25
  channel: "APP-SECURITY-AUTH-SIGNIN",
25
26
  group: "out",
26
- callback: (t) => {
27
- this.accessToken = t.payload.accessToken;
27
+ callback: (s) => {
28
+ this.accessToken = s.payload.accessToken;
28
29
  }
29
30
  }), this.init = Promise.all([this.getBaseUrlAsync(), this.updateSecurityAsync()]);
30
31
  }
31
32
  async getBaseUrlAsync() {
32
- const s = (await this.msgBus.dispatchAsync({
33
+ const n = (await this.msgBus.request({
33
34
  channel: "APP-CONFIG-GET"
34
- })).payload, t = u(this.name, f), a = Object.entries(s.apis).find((n) => n[0].toLowerCase() === t?.toLowerCase());
35
- this.baseUrl = a?.[1].url || s.baseUrl;
35
+ })).payload, t = f(this.name, this.apiSuffixes), s = Object.entries(n.apis).find((a) => a[0].toLowerCase() === t?.toLowerCase());
36
+ s || console.warn(`API "${t}" is not defined in the current configuration. Using default configuration.`), this.baseUrl = s?.[1].url || n.baseUrl;
36
37
  }
37
38
  async updateSecurityAsync() {
38
39
  if (!this.accessToken) {
39
- const e = await this.msgBus.dispatchAsync({
40
+ const e = await this.msgBus.request({
40
41
  channel: "APP-SECURITY-GET-CONTEXT"
41
42
  });
42
43
  this.accessToken = e.payload.accessToken;
@@ -44,65 +45,65 @@ class R {
44
45
  return this.accessToken;
45
46
  }
46
47
  async addAuthorizationAsync(e) {
47
- const s = await this.updateSecurityAsync();
48
- if (!s)
48
+ const n = await this.updateSecurityAsync();
49
+ if (!n)
49
50
  throw r.create({
50
51
  status: o.UNAUTHORIZED
51
52
  });
52
- const t = "Authorization", a = e.headers, n = `Bearer ${s}`;
53
- if (a instanceof Headers)
54
- a.set(t, n);
53
+ const t = "Authorization", s = e.headers, a = `Bearer ${n}`;
54
+ if (s instanceof Headers)
55
+ s.set(t, a);
55
56
  else
56
57
  throw new Error("Unsupported headers");
57
58
  }
58
59
  async executeRequestInternalAsync(e) {
59
60
  try {
60
- let s = !0;
61
+ let n = !0;
61
62
  const t = e.callbacks && e.callbacks.onBeforeSendRequest;
62
63
  if (t) {
63
- const a = {
64
+ const s = {
64
65
  request: e,
65
66
  cancel: !1,
66
67
  handled: !1
67
68
  };
68
- if (await t(a), a.cancel)
69
- if (s = !1, e.status = "canceled", a.handled)
70
- e.result = a.result;
69
+ if (await t(s), s.cancel)
70
+ if (n = !1, e.status = "canceled", s.handled)
71
+ e.result = s.result;
71
72
  else
72
73
  throw new Error("The request was aborted");
73
74
  }
74
- if (s) {
75
+ if (n) {
75
76
  e.status = "executing";
76
- const a = await this.fetcher.fetch(e.url, e);
77
- r.assert(a, e);
78
- let n = e.callbacks && e.callbacks.onResponseRead;
79
- n || (n = async (l) => {
80
- const h = await p(a, e);
77
+ const s = await this.fetcher.fetch(e.url, e);
78
+ r.assert(s, e);
79
+ let a = e.callbacks && e.callbacks.onResponseRead;
80
+ a || (a = async (l) => {
81
+ const h = await u(s, e);
81
82
  l.result = h;
82
83
  });
83
- const i = {
84
- response: a
84
+ const c = {
85
+ response: s
85
86
  };
86
- await n(i), e.result = i.result, e.status = "succeeded";
87
+ await a(c), e.result = c.result, e.status = "succeeded";
87
88
  }
88
- } catch (s) {
89
- throw e.status = "failed", s;
89
+ } catch (n) {
90
+ throw e.status = "failed", n;
90
91
  }
91
92
  return e;
92
93
  }
93
94
  async executeRequestAsync(e) {
94
- let s = 0;
95
+ let n = 0;
95
96
  do
96
97
  try {
97
98
  return e.useAuth && await this.addAuthorizationAsync(e), await this.executeRequestInternalAsync(e);
98
99
  } catch (t) {
99
100
  if (t instanceof r) {
100
- if (s > 0 || t.status === o.UPGRADE_REQUIRED)
101
+ if (n > 0 || t.status === o.UPGRADE_REQUIRED)
101
102
  throw t;
102
103
  if (t.status === o.UNAUTHORIZED) {
103
- t.response?.headers?.get("token-expired") ? await this.msgBus.dispatchAsync({
104
+ t.response?.headers?.get("token-expired") ? await this.msgBus.request({
104
105
  channel: "APP-SECURITY-AUTH-REFRESH"
105
- }) : await this.msgBus.dispatchAsync({
106
+ }) : await this.msgBus.request({
106
107
  channel: "APP-SECURITY-REQUEST-AUTH"
107
108
  });
108
109
  continue;
@@ -111,7 +112,7 @@ class R {
111
112
  }
112
113
  throw t;
113
114
  } finally {
114
- s++;
115
+ n++;
115
116
  }
116
117
  while (!0);
117
118
  }
@@ -136,7 +137,7 @@ class R {
136
137
  }
137
138
  }
138
139
  export {
139
- R as ClientBase,
140
- u as extractApiName
140
+ g as ClientBase,
141
+ f as extractApiName
141
142
  };
142
143
  //# sourceMappingURL=client.es.js.map