arrmatura 5.2.0 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/index.ts +20 -0
  2. package/package.json +14 -44
  3. package/src/core/composition.ts +71 -0
  4. package/src/core/conditionals.ts +80 -0
  5. package/src/core/elementary.ts +40 -0
  6. package/src/core/fragment.ts +21 -0
  7. package/src/core/index.ts +19 -0
  8. package/src/core/iterations.ts +121 -0
  9. package/src/core/root.ts +46 -0
  10. package/src/core/routing.ts +37 -0
  11. package/src/core/selection.ts +57 -0
  12. package/src/core/slot.ts +36 -0
  13. package/src/ctx/Ctx.ts +424 -0
  14. package/src/ctx/CtxNode.ts +159 -0
  15. package/src/utils/compileExpression.ts +126 -0
  16. package/src/utils/stringify.ts +39 -0
  17. package/LICENSE +0 -21
  18. package/README.md +0 -54
  19. package/commons/auth/AuthService.ts +0 -111
  20. package/commons/auth/UserService.ts +0 -57
  21. package/commons/auth/index.ts +0 -5
  22. package/commons/auth/user.xml +0 -64
  23. package/commons/components/buttons.xml +0 -25
  24. package/commons/components/index.ts +0 -13
  25. package/commons/components/inputs.xml +0 -33
  26. package/commons/components/layouts.xml +0 -77
  27. package/commons/components/media.xml +0 -21
  28. package/commons/components/modal.xml +0 -37
  29. package/commons/components/navigation.xml +0 -73
  30. package/commons/components/popups.xml +0 -12
  31. package/commons/components/searchbar.xml +0 -54
  32. package/commons/components/table.xml +0 -140
  33. package/commons/components/toasts.xml +0 -18
  34. package/commons/components/viewport.xml +0 -48
  35. package/commons/forms/FieldItem.xml +0 -20
  36. package/commons/forms/FormController.ts +0 -87
  37. package/commons/forms/Item.ts +0 -132
  38. package/commons/forms/ItemCollectionController.ts +0 -113
  39. package/commons/forms/ItemController.ts +0 -91
  40. package/commons/forms/MultiEnumField.xml +0 -44
  41. package/commons/forms/MultivalueController.ts +0 -49
  42. package/commons/forms/NewItemController.ts +0 -46
  43. package/commons/forms/SmartareaField.xml +0 -51
  44. package/commons/forms/SuggestionController.ts +0 -80
  45. package/commons/forms/SuggestionField.xml +0 -28
  46. package/commons/forms/fields.xml +0 -151
  47. package/commons/forms/form.xml +0 -37
  48. package/commons/forms/index.ts +0 -29
  49. package/commons/index.ts +0 -6
  50. package/commons/services/ApiClientService.ts +0 -32
  51. package/commons/services/ErrorHandlingService.ts +0 -11
  52. package/commons/services/FirebaseService.ts +0 -185
  53. package/commons/services/GSheetsService.ts +0 -120
  54. package/commons/services/HeartbeatService.ts +0 -35
  55. package/commons/services/Invoke.ts +0 -29
  56. package/commons/services/JsonpService.ts +0 -18
  57. package/commons/services/Loader.ts +0 -17
  58. package/commons/services/MetadataService.ts +0 -50
  59. package/commons/services/NavigationService.ts +0 -74
  60. package/commons/services/Service.ts +0 -62
  61. package/commons/services/ServiceWorker.ts +0 -111
  62. package/commons/services/Storage.ts +0 -55
  63. package/commons/services/ToastService.ts +0 -61
  64. package/commons/services/index.ts +0 -13
  65. package/core/Arrmatura.ts +0 -79
  66. package/core/CNode.ts +0 -111
  67. package/core/Component.ts +0 -424
  68. package/core/cnodes/composition.ts +0 -100
  69. package/core/cnodes/conditionals.ts +0 -52
  70. package/core/cnodes/elementary.ts +0 -44
  71. package/core/cnodes/iterations.ts +0 -92
  72. package/core/cnodes/routing.ts +0 -25
  73. package/core/compileNode.ts +0 -39
  74. package/core/expression.ts +0 -73
  75. package/core/index.ts +0 -1
  76. package/core/register.ts +0 -43
  77. package/core/utils.ts +0 -23
  78. package/core-web/WebPlatform.ts +0 -25
  79. package/core-web/attributes.ts +0 -218
  80. package/core-web/elements.ts +0 -81
  81. package/core-web/index.ts +0 -28
  82. package/core-web/reflow.ts +0 -30
  83. package/core-web/support.ts +0 -27
  84. package/core-web/type.ts +0 -18
  85. package/docs/index.js +0 -485
  86. package/lib/array/arrayGroupBy.ts +0 -19
  87. package/lib/array/arraySortBy.ts +0 -49
  88. package/lib/array/arrayToObject.ts +0 -18
  89. package/lib/array/arrayish.ts +0 -7
  90. package/lib/array/index.ts +0 -4
  91. package/lib/crypto/index.ts +0 -25
  92. package/lib/date/index.ts +0 -127
  93. package/lib/func/curry.ts +0 -11
  94. package/lib/func/fx.ts +0 -56
  95. package/lib/func/identity.ts +0 -6
  96. package/lib/func/nextId.ts +0 -9
  97. package/lib/func/noop.ts +0 -6
  98. package/lib/geo/index.js +0 -22
  99. package/lib/index.ts +0 -17
  100. package/lib/object/index.ts +0 -69
  101. package/lib/parsing/codus.ts +0 -25
  102. package/lib/parsing/compiler.ts +0 -26
  103. package/lib/parsing/scalarParse.ts +0 -25
  104. package/lib/parsing/urls.ts +0 -91
  105. package/lib/parsing/xml.ts +0 -117
  106. package/lib/resources/l10n.ts +0 -40
  107. package/lib/resources/resources.ru.ts +0 -20
  108. package/lib/resources/resources.ts +0 -20
  109. package/lib/string/index.ts +0 -58
  110. package/lib/support/createListeners.ts +0 -12
@@ -1,55 +0,0 @@
1
- const parse = (s: string | null) => (s ? JSON.parse(s) : undefined);
2
-
3
- class MemoryStore {
4
- #map = new Map<string, string>();
5
-
6
- clear() {
7
- return this.#map.clear();
8
- }
9
- getItem(key: string) {
10
- return this.#map.get(key) || null;
11
- }
12
-
13
- setItem(key: string, value: string): void {
14
- this.#map.set(key, value);
15
- }
16
- removeItem(key: string): void {
17
- this.#map.delete(key);
18
- }
19
- }
20
-
21
- export class Storage {
22
- cache: Hash = {};
23
- storage: Omit<MemoryStore, 'prototype'>;
24
-
25
- constructor(mode?: 'local' | 'transient' | 'session', readonly ns = '') {
26
- this.storage =
27
- mode === 'local' ? window.localStorage : mode === 'session' ? window.sessionStorage : new MemoryStore();
28
- }
29
-
30
- clear() {
31
- this.cache = {};
32
- return this.storage.clear();
33
- }
34
-
35
- get(key: string) {
36
- return this.cache[key] || (this.cache[key] = parse(this.storage.getItem(key + this.ns)));
37
- }
38
-
39
- set(key: string, val: unknown) {
40
- this.cache[key] = val;
41
- if (val) {
42
- this.storage.setItem(key + this.ns, JSON.stringify(val));
43
- } else {
44
- this.storage.removeItem(key + this.ns);
45
- }
46
- }
47
-
48
- assign(delta: Delta) {
49
- Object.entries(delta).forEach(([key, val = null]) => this.set(key, val));
50
- }
51
-
52
- transform(key: string, fn: Pipe) {
53
- return this.set(key, fn(this.get(key)));
54
- }
55
- }
@@ -1,61 +0,0 @@
1
- import { HeartbeatService } from './HeartbeatService';
2
- import { Service } from './Service';
3
-
4
- export type Toast = {
5
- message: string;
6
- link?: string;
7
- mode: 'error' | 'warning' | 'info' | '';
8
- id: string;
9
- ttl: number;
10
- timeout?: number;
11
- counter?: number;
12
- };
13
-
14
- export class ToastSender extends Service {
15
- onData(data: Delta) {
16
- this.emit('toaster.send', data);
17
- }
18
- }
19
-
20
- export class ToastService extends Service {
21
- items: Toast[] = [];
22
-
23
- heartbeat = new HeartbeatService(() => this.emit('this.tick', {}));
24
-
25
- setItems(items: Toast[]) {
26
- this.heartbeat.setActive(!!items.length);
27
- this.items = items;
28
- }
29
-
30
- onSend(data: Toast, { items }: this) {
31
- const now = Date.now();
32
- const id = String(data.id || now);
33
- const close = () => this.emit('this.close', { id });
34
- const toast = {
35
- ...data,
36
- mode: data?.message?.startsWith('error') ? 'error' : data.mode,
37
- id,
38
- close,
39
- ttl: now + (data.timeout || 6000),
40
- };
41
- const prev = items.find((e) => e.id === id);
42
- if (prev) {
43
- toast.counter = 1 + (prev.counter || 1);
44
- }
45
- return {
46
- items: [toast, ...items.filter((e) => e !== prev)],
47
- };
48
- }
49
-
50
- onTick(_: unknown, { items }: this) {
51
- const now = Date.now();
52
-
53
- return { items: items.filter((e: Toast) => e.ttl > now) };
54
- }
55
-
56
- onClose({ id }: Datum, { items }: this) {
57
- return {
58
- items: items.filter((e) => e.id !== id),
59
- };
60
- }
61
- }
@@ -1,13 +0,0 @@
1
- export { NavigationService } from './NavigationService';
2
- export { ServiceWorker } from './ServiceWorker';
3
- export { Service } from './Service';
4
- export { ToastService } from './ToastService';
5
- export { Loader } from './Loader';
6
- export { Invoke } from './Invoke';
7
- export { ErrorHandlingService } from './ErrorHandlingService';
8
- export { FormController } from '../forms/FormController';
9
- export * from './MetadataService';
10
- export * from './GSheetsService';
11
- export * from './ApiClientService';
12
- export * from './FirebaseService';
13
- export * from './MetadataService';
package/core/Arrmatura.ts DELETED
@@ -1,79 +0,0 @@
1
- import { CNode } from './CNode';
2
- import { compileNodes } from './compileNode';
3
- import { Component } from './Component';
4
- import { xmlParse } from '../lib/parsing/xml';
5
- import { registerTypes } from './register';
6
-
7
- export class Arrmatura extends Component<CArrmaturaNode> implements IArrmatura {
8
- rootElement: any;
9
- reflowId?: unknown;
10
-
11
- get displayName(): string {
12
- return 'Arrmatura';
13
- }
14
-
15
- get platform(): IPlatform {
16
- return this.node.platform;
17
- }
18
-
19
- requestReflow() {
20
- if (this.reflowId) return;
21
- this.reflowId = setTimeout(() => {
22
- this.platform.reflow(this);
23
- this.reflowId = undefined;
24
- }, 10);
25
- }
26
-
27
- res(key: string): any {
28
- const [id, ...deep] = key.split('.');
29
- const { resources = {} } = this.node;
30
- const target = id ? resources?.[id] : resources;
31
- if (!target || deep.length === 0) {
32
- return target;
33
- }
34
- if (deep.length === 1) {
35
- return target[deep[0]];
36
- }
37
- return deep.reduce((r, k) => (r ? r[k] : null), target);
38
- }
39
-
40
- pipe(key: string) {
41
- const [id, ...deep] = key.split('.');
42
- const target = this.node.functions?.[id];
43
- if (!target || deep.length === 0) {
44
- return target;
45
- }
46
- if (deep.length === 1) {
47
- return (target as Hash)[deep[0]];
48
- }
49
- return deep.reduce((r, k) => (r ? (r as Hash)[k] : null), target);
50
- }
51
- }
52
-
53
- export class CArrmaturaNode extends CNode<Arrmatura> {
54
- functions?: Hash;
55
- resources: Hash<any> | undefined;
56
- platform: IPlatform;
57
-
58
- constructor(template: string, { types, functions, resources }: ArrmaturaOptions, platform: IPlatform) {
59
- super();
60
-
61
- registerTypes(types);
62
-
63
- this.functions = functions;
64
- this.resources = resources;
65
- this.platform = platform;
66
-
67
- this.content = compileNodes(xmlParse(template));
68
- }
69
-
70
- get ComponentConstructor() {
71
- return Arrmatura;
72
- }
73
-
74
- launch(config = {}) {
75
- const arrmatura = this.createComponent();
76
-
77
- arrmatura.up(config, true);
78
- }
79
- }
package/core/CNode.ts DELETED
@@ -1,111 +0,0 @@
1
- import { nextId, identity } from '../lib';
2
- import { Component } from './Component';
3
- import { compileExpression, compilePipeExpression } from './expression';
4
-
5
- /**
6
- * Design-time Component class.
7
- */
8
- export abstract class CNode<T extends Component = Component> implements INode<T> {
9
- content?: ComponentContent;
10
- uid: Uid = nextId('N');
11
- refId?: string;
12
- private propertyResolvers: Array<PropertyResolver> = [];
13
- private initialState?: Hash;
14
- initializers: Array<(c: IComponent) => undefined | ComponentSubsription> = [];
15
- tag: any;
16
-
17
- abstract get ComponentConstructor(): new (node: INode<T>, parent?: IComponent, scope?: IScope) => T;
18
-
19
- createComponent(parent?: IComponent, scope?: Component): T {
20
- return new this.ComponentConstructor(this as INode<T>, parent, scope);
21
- }
22
-
23
- addInitialState(values: Hash) {
24
- this.initialState = Object.entries(values).reduce((acc, [key, val]) => {
25
- acc[key] = val;
26
- return acc;
27
- }, this.initialState || {});
28
- return this;
29
- }
30
-
31
- addPropertyResolver(getter: PropertyGetter, propKey: string) {
32
- this.propertyResolvers.push((c: IComponent, delta: Delta) => {
33
- delta[propKey] = getter(c);
34
- return delta;
35
- });
36
- return this;
37
- }
38
-
39
- addPropertiesResolver(getter: PropertyGetter) {
40
- this.propertyResolvers.push((c: IComponent, delta: Delta) => {
41
- const value = getter(c);
42
- if (value && typeof value === 'object') {
43
- Object.entries(value).forEach(([key, val]) => {
44
- delta[key] = val;
45
- });
46
- }
47
- return delta;
48
- });
49
- return this;
50
- }
51
-
52
- addPropertyConnector(expr: Expression, getter: (x: unknown) => unknown) {
53
- const { key, pipec } = compilePipeExpression(expr);
54
- this.initializers.push((c: IComponent) => c.connect(key, (rr: unknown) => getter(pipec(c, rr))));
55
- }
56
-
57
- addEmitter(expr: Expression, k: PropertyKey) {
58
- const { key, pipec } = compilePipeExpression(expr);
59
- this.initializers.push((c) => ({
60
- payload: { [k]: (data: unknown) => c.$scope?.emit(key, pipec(c, data) as Delta) },
61
- }));
62
- }
63
-
64
- resolveInitialProps(c: IComponent) {
65
- return this.resolveProps(c, { ...this.initialState });
66
- }
67
-
68
- resolveProps(c: IComponent, props: Delta = {}) {
69
- return this.propertyResolvers.reduce((delta, resolver) => resolver(c, delta), props);
70
- }
71
-
72
- compileAttribute(k: string, v: unknown) {
73
- if (k === 'id') {
74
- this.addInitialState({ [k]: v });
75
- } else if (k.startsWith('ui:')) {
76
- const sv = String(v);
77
- if (k === 'ui:ref') {
78
- this.refId = sv;
79
- } else if (k === 'ui:props') {
80
- if (sv[0] === '<' && sv[1] === '-') {
81
- this.addPropertyConnector(sv.slice(2), identity);
82
- } else {
83
- this.addPropertiesResolver(compileExpression(v));
84
- }
85
- }
86
- } else {
87
- if (typeof v !== 'string') {
88
- this.addInitialState({ [k]: v });
89
- } else {
90
- if (v[0] === '<' && v[1] === '-') {
91
- this.addPropertyConnector(v.slice(2), (rr) => ({ [k]: rr }));
92
- } else if (v[0] === '-' && v[1] === '>') {
93
- this.addEmitter(v.slice(2), k);
94
- } else {
95
- if (!v.includes('{') && v[0] !== ':') {
96
- this.addInitialState({ [k]: v });
97
- } else {
98
- this.addPropertyResolver(compileExpression(v), k);
99
- }
100
- }
101
- }
102
- }
103
- return this;
104
- }
105
-
106
- compileAttributes(attrs?: Hash) {
107
- if (attrs) {
108
- Object.entries(attrs).forEach((keyValue) => this.compileAttribute(...keyValue));
109
- }
110
- }
111
- }