@pcg/dynamic-components 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (61) hide show
  1. package/dist/index.d.ts +6 -6
  2. package/dist/index.js +52 -52
  3. package/dist/index.js.map +1 -1
  4. package/package.json +15 -3
  5. package/.turbo/turbo-build.log +0 -16
  6. package/CHANGELOG.md +0 -24
  7. package/eslint.config.cjs +0 -14
  8. package/src/assertions/basic.ts +0 -7
  9. package/src/assertions/containers.ts +0 -8
  10. package/src/assertions/index.ts +0 -6
  11. package/src/assertions/paths.ts +0 -12
  12. package/src/assertions/rich-text.ts +0 -16
  13. package/src/assertions/yjs.ts +0 -25
  14. package/src/data-objects/data-object.ts +0 -34
  15. package/src/data-objects/index.ts +0 -3
  16. package/src/data-objects/rich-text.ts +0 -38
  17. package/src/dynamic-components/fractional-indexing.ts +0 -321
  18. package/src/dynamic-components/index.ts +0 -6
  19. package/src/dynamic-components/paths.ts +0 -194
  20. package/src/dynamic-components/registry/chats.ts +0 -24
  21. package/src/dynamic-components/registry/content.ts +0 -118
  22. package/src/dynamic-components/registry/forms.ts +0 -525
  23. package/src/dynamic-components/registry/index.ts +0 -6
  24. package/src/dynamic-components/registry/layout.ts +0 -86
  25. package/src/dynamic-components/registry/uikit-dynamic-component.ts +0 -84
  26. package/src/dynamic-components/tools.ts +0 -195
  27. package/src/dynamic-components/types.ts +0 -237
  28. package/src/index.ts +0 -7
  29. package/src/paths/array-keys.ts +0 -164
  30. package/src/paths/array-ops.ts +0 -124
  31. package/src/paths/basic-ops.ts +0 -181
  32. package/src/paths/constants.ts +0 -1
  33. package/src/paths/index.ts +0 -7
  34. package/src/paths/tools.ts +0 -42
  35. package/src/paths/types.ts +0 -133
  36. package/src/y-components/index.ts +0 -3
  37. package/src/y-components/tools.ts +0 -234
  38. package/src/y-components/types.ts +0 -19
  39. package/src/y-tools/array-path-ops.ts +0 -240
  40. package/src/y-tools/basic-path-ops.ts +0 -189
  41. package/src/y-tools/index.ts +0 -6
  42. package/src/y-tools/tools.ts +0 -122
  43. package/src/y-tools/types.ts +0 -32
  44. package/src/y-tools/y-array-keys.ts +0 -47
  45. package/tests/assertions/basic-types.test.ts +0 -78
  46. package/tests/assertions/containers.test.ts +0 -72
  47. package/tests/assertions/paths.test.ts +0 -23
  48. package/tests/assertions/yjs.test.ts +0 -33
  49. package/tests/dynamic-components/paths.test.ts +0 -171
  50. package/tests/dynamic-components/tools.test.ts +0 -121
  51. package/tests/paths/array-keys.test.ts +0 -182
  52. package/tests/paths/array-ops.test.ts +0 -164
  53. package/tests/paths/basic-ops.test.ts +0 -263
  54. package/tests/paths/tools.test.ts +0 -55
  55. package/tests/y-components/tools.test.ts +0 -198
  56. package/tests/y-tools/array-base-ops.test.ts +0 -55
  57. package/tests/y-tools/array-path-ops.test.ts +0 -95
  58. package/tsconfig.json +0 -13
  59. package/tsconfig.lib.json +0 -13
  60. package/tsdown.config.ts +0 -18
  61. package/vitest.config.ts +0 -19
@@ -1,194 +0,0 @@
1
- import { isString } from '@/assertions/index.js';
2
- import { isArrayKey } from '@/paths/index.js';
3
-
4
- import {
5
- isCollectionComponent,
6
- isColumnComponent, isRepeatableCollectionComponent, isRowComponent,
7
- } from './registry/index.js';
8
- import { DynamicComponent } from './types.js';
9
-
10
- /**
11
- * Get array with components founded by rpath
12
- *
13
- * @example
14
- * const components = [
15
- * {
16
- * id: "xxx",
17
- * component: "collection",
18
- * props: {
19
- * components: [
20
- * {
21
- * id: "yyy",
22
- * component: "text-input",
23
- * props: {
24
- * label: "Title"
25
- * }
26
- * }
27
- * ]
28
- * }
29
- * }
30
- * ]
31
- *
32
- * const { pathWithComponents } = getComponentsSubtreeByRPath(components, ['xxx', 'yyy']);
33
- *
34
- * // pathWithComponents
35
- * // [
36
- * // {
37
- * // id: "xxx",
38
- * // component: "collection",
39
- * // ...
40
- * // },
41
- * // {
42
- * // id: "yyy",
43
- * // component: "text-input",
44
- * // ...
45
- * // }
46
- * // ]
47
- *
48
- */
49
- export const getComponentsSubtreeByRPath = (components: DynamicComponent[], rpath: string[]) => {
50
- const pathWithComponents: DynamicComponent[] = [];
51
-
52
- deepGetComponentsSubtreeByRPath(components, rpath, pathWithComponents);
53
-
54
- return {
55
- pathWithComponents,
56
- complete: pathWithComponents.length === rpath.length,
57
- };
58
- };
59
-
60
- const deepGetComponentsSubtreeByRPath = (components: DynamicComponent[], rpath: string[], pathWithComponents: DynamicComponent[]) => {
61
- const id = rpath[0];
62
-
63
- const component = components.find((cmp) => cmp.id === id);
64
-
65
- if (!component) {
66
- return;
67
- }
68
-
69
- pathWithComponents.push(component);
70
-
71
- if (!Array.isArray(component.props.components)) {
72
- return;
73
- }
74
-
75
- deepGetComponentsSubtreeByRPath(component.props.components, rpath.slice(1), pathWithComponents);
76
- };
77
-
78
- /**
79
- * Get array with components founded by values path.
80
- *
81
- * @example
82
- * const components = [
83
- * {
84
- * id: "xxx",
85
- * component: "collection",
86
- * props: {
87
- * name: "seo",
88
- * components: [
89
- * {
90
- * id: "yyy",
91
- * component: "text-input",
92
- * props: {
93
- * label: "Title",
94
- * name: "title",
95
- * }
96
- * }
97
- * ]
98
- * }
99
- * }
100
- * ]
101
- *
102
- * const { pathWithComponents } = getComponentsSubtreeByPath(components, ['seo', 'title']);
103
- *
104
- * // pathWithComponents
105
- * // [
106
- * // {
107
- * // id: "xxx",
108
- * // component: "collection",
109
- * // ...
110
- * // },
111
- * // {
112
- * // id: "yyy",
113
- * // component: "text-input",
114
- * // ...
115
- * // }
116
- * // ]
117
- *
118
- */
119
- export const getComponentsSubtreeByPath = (components: DynamicComponent[], path: (string | number)[]) => {
120
- const pathWithComponents: DynamicComponent[] = [];
121
- const complete = true;
122
-
123
- deepGetComponentsSubtreeByPath(components, path, pathWithComponents, complete);
124
-
125
- return {
126
- pathWithComponents,
127
- complete,
128
- };
129
- };
130
-
131
- const deepFindComponentPathKey = (components: DynamicComponent[], key: string): DynamicComponent | null => {
132
- for (const component of components) {
133
- if ((component.props.name && component.props.name === key) || component.id === key) {
134
- return component;
135
- }
136
-
137
- if (isRowComponent(component) || isColumnComponent(component)) {
138
- const result = deepFindComponentPathKey(component.props.components, key);
139
- if (result) {
140
- return result;
141
- }
142
- }
143
- }
144
-
145
- return null;
146
- };
147
-
148
- const deepGetComponentsSubtreeByPath = (
149
- components: DynamicComponent[],
150
- path: (string | number)[],
151
- pathWithComponents: DynamicComponent[],
152
- complete: boolean,
153
- ) => {
154
- const key = path[0];
155
-
156
- if (!isString(key)) {
157
- complete = false;
158
-
159
- return;
160
- }
161
-
162
- const component = deepFindComponentPathKey(components, key);
163
-
164
- if (!component) {
165
- complete = false;
166
-
167
- return;
168
- }
169
-
170
- pathWithComponents.push(component);
171
-
172
- /**
173
- * Deep dive if repeatable collection.
174
- *
175
- * If next key is array key find in props.components next key after array key
176
- *
177
- * @example
178
- * path = ['fields', 'id:xxx', 'title']
179
- *
180
- * cpnst key = 'fields';
181
- * const nextKey = 'id:xxx', // array key
182
- * const nextKeyAfterArrayKey = 'title';
183
- */
184
- if (isRepeatableCollectionComponent(component)) {
185
- const nextKey = path[1];
186
- if (isArrayKey(nextKey) && path[2]) {
187
- deepGetComponentsSubtreeByPath(component.props.components, path.slice(2), pathWithComponents, complete);
188
- }
189
- }
190
-
191
- if (isCollectionComponent(component)) {
192
- deepGetComponentsSubtreeByPath(component.props.components, path.slice(1), pathWithComponents, complete);
193
- }
194
- };
@@ -1,24 +0,0 @@
1
- import { RichText } from '../../data-objects/rich-text.js';
2
- import { DynamicComponent } from '../types.js';
3
-
4
- /* Text Message */
5
- export interface DChatTextMessage extends DynamicComponent {
6
- component: 'chat-text-message';
7
- props: {
8
- content: RichText;
9
- };
10
- }
11
-
12
- export const isChatTextMessageComponent = (component: DynamicComponent): component is DChatTextMessage => component.component === 'chat-text-message';
13
-
14
- /* Message Delay */
15
- export interface DChatMessageDelay extends DynamicComponent {
16
- component: 'chat-message-delay';
17
- props: {
18
- delay: number;
19
- typing: boolean;
20
- };
21
- }
22
-
23
- // eslint-disable-next-line max-len
24
- export const isChatMessageDelayComponent = (component: DynamicComponent): component is DChatMessageDelay => component.component === 'chat-message-delay';
@@ -1,118 +0,0 @@
1
- import { RichText } from '../../data-objects/rich-text.js';
2
- import { DynamicComponent } from '../types.js';
3
-
4
- /* TEXT INPUT */
5
- export interface DRichText extends DynamicComponent {
6
- component: 'rich-text';
7
- props: {
8
- content: RichText;
9
- };
10
- }
11
-
12
- export const isRichTextComponent = (component: DynamicComponent): component is DRichText => component.component === 'rich-text';
13
-
14
- /* RowSettings */
15
- export interface DEmbedCode extends DynamicComponent {
16
- component: 'embed-code';
17
- props: {
18
- js?: string;
19
- css?: string;
20
- html?: string;
21
- visible?: string;
22
- };
23
- }
24
-
25
- export const isEmbedCodeComponent = (component: DynamicComponent): component is DEmbedCode => {
26
- return component.component === 'embed-code';
27
- };
28
-
29
- /* Image */
30
- export interface DImage extends DynamicComponent {
31
- component: 'embed-code';
32
- props: {
33
- imageId: string;
34
- };
35
- }
36
-
37
- export const isImageComponent = (component: DynamicComponent): component is DImage => component.component === 'image';
38
-
39
- /* Legacy Content */
40
- export interface DLegacyContent extends DynamicComponent {
41
- component: 'legacy-content';
42
- props: {
43
- html: string;
44
- };
45
- }
46
-
47
- export const isLegacyContentComponent = (component: DynamicComponent): component is DLegacyContent => component.component === 'legacy-content';
48
-
49
- /* Bible Quote */
50
- export interface DBibleQuote extends DynamicComponent {
51
- component: 'bible-quote';
52
- props: {
53
- verseId: string;
54
- };
55
- }
56
-
57
- export const isBibleQuoteComponent = (component: DynamicComponent): component is DBibleQuote => component.component === 'bible-quote';
58
-
59
- /* Bible Passage */
60
- export interface DBiblePassage extends DynamicComponent {
61
- component: 'bible-passage';
62
- props: {
63
- passage: string;
64
- };
65
- }
66
-
67
- export const isBiblePassageComponent = (component: DynamicComponent): component is DBiblePassage => component.component === 'bible-passage';
68
-
69
- /* TESTS */
70
-
71
- export interface TestItemVariant {
72
- id: string;
73
- content: RichText;
74
- feedback?: RichText;
75
- correct?: boolean;
76
- }
77
-
78
- export interface TestItem {
79
- id: string;
80
- content: RichText;
81
- variants: TestItemVariant[];
82
- }
83
-
84
- export interface DTest extends DynamicComponent {
85
- component: 'test';
86
- props: {
87
- title?: string;
88
- items: TestItem[];
89
- milestone?: string;
90
- };
91
- }
92
-
93
- export const isTestComponent = (component: DynamicComponent): component is DTest => component.component === 'test';
94
-
95
- export interface DStatement extends DynamicComponent {
96
- component: 'statement';
97
- props: {
98
- content: RichText;
99
- };
100
- }
101
-
102
- export const isStatementComponent = (component: DynamicComponent): component is DStatement => component.component === 'statement';
103
-
104
- export interface DPractice extends DynamicComponent {
105
- component: 'practice';
106
- props: {
107
- title?: string;
108
- content: RichText;
109
-
110
- /**
111
- * Date when the practice should be checked in ISO 8601 format
112
- * @example '2023-10-01T00:08:00Z'
113
- */
114
- checkAt?: string;
115
- };
116
- }
117
-
118
- export const isPracticeComponent = (component: DynamicComponent): component is DPractice => component.component === 'practice';