@resistdesign/voltra 3.0.0-alpha.27 → 3.0.0-alpha.29

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.
@@ -23,6 +23,20 @@ export type RouteAdapter = {
23
23
  /** Optional capability check for backward navigation. */
24
24
  canGoBack?: () => boolean;
25
25
  };
26
+ /**
27
+ * Optional runtime integration for root Route provider mode.
28
+ *
29
+ * Use this to layer platform-specific side effects (for example, native
30
+ * hardware back wiring) without coupling core app routing to a platform API.
31
+ */
32
+ export type RouteRuntimeIntegration = {
33
+ /**
34
+ * Start integration against the active adapter.
35
+ *
36
+ * Return a cleanup function when teardown is required.
37
+ */
38
+ setup: (adapter: RouteAdapter) => void | (() => void);
39
+ };
26
40
  /**
27
41
  * Supported query value types for route serialization.
28
42
  */
@@ -136,5 +150,9 @@ export type RouteProps<ParamsType extends Record<string, any>> = {
136
150
  * Optional external URL ingress for root provider mode only.
137
151
  */
138
152
  ingress?: UniversalRouteIngress;
153
+ /**
154
+ * Optional runtime integration hook for root provider mode only.
155
+ */
156
+ runtimeIntegration?: RouteRuntimeIntegration;
139
157
  };
140
158
  export declare const Route: <ParamsType extends Record<string, any>>(props: PropsWithChildren<RouteProps<ParamsType>>) => import("react/jsx-runtime").JSX.Element | null;
@@ -55,16 +55,6 @@ export type UniversalRouteIngress = {
55
55
  */
56
56
  mapURLToPath?: (url: string) => string;
57
57
  };
58
- type ReactNativeBackHandler = {
59
- addEventListener: (eventName: "hardwareBackPress", listener: () => boolean) => {
60
- remove?: () => void;
61
- } | void;
62
- removeEventListener?: (eventName: "hardwareBackPress", listener: () => boolean) => void;
63
- };
64
- /**
65
- * Safely resolve React Native BackHandler for Android runtimes only.
66
- */
67
- export declare const tryGetReactNativeBackHandler: () => ReactNativeBackHandler | undefined;
68
58
  /**
69
59
  * Detect whether browser history is available at runtime.
70
60
  */
@@ -81,4 +71,3 @@ export declare const createNativeRouteAdapter: (initialPath?: string, ingress?:
81
71
  * Create a runtime-selected RouteAdapter for web/native environments.
82
72
  */
83
73
  export declare const createUniversalAdapter: (options?: CreateUniversalAdapterOptions) => RouteAdapter;
84
- export {};
package/build/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { getPotentialJSONValue, getPathArray } from '../chunk-GYWRAW3Y.js';
2
+ import '../chunk-I2KLQ2HA.js';
1
3
  import { SyntaxKind, isLiteralTypeNode, isStringLiteral, isNumericLiteral, createSourceFile, ScriptTarget } from 'typescript';
2
4
 
3
- // src/build/TypeMapping.ts
4
5
  var convertASTToMap = (node, map = {}, parentName) => {
5
6
  node.forEachChild((child) => {
6
7
  const { kind: childKind } = child;
@@ -26,17 +27,6 @@ var convertASTToMap = (node, map = {}, parentName) => {
26
27
  return map;
27
28
  };
28
29
 
29
- // src/common/Routing.ts
30
- var PATH_DELIMITER = "/";
31
- var getPotentialJSONValue = (value) => {
32
- try {
33
- return JSON.parse(value);
34
- } catch (error) {
35
- return value;
36
- }
37
- };
38
- var getPathArray = (path, delimiter = PATH_DELIMITER, filterEmptyOutput = false, filterEmptyInput = true, useJson = true, uriDecodeParts = true) => path.split(delimiter).filter(filterEmptyInput ? (p) => p !== "" : () => true).map(uriDecodeParts ? decodeURIComponent : (x) => x).map(useJson ? getPotentialJSONValue : (p) => p).filter(filterEmptyOutput ? (p) => p ?? false : () => true);
39
-
40
30
  // src/common/TypeParsing/ParsingUtils/extractCommentTags.ts
41
31
  var TAG_NAME_PATH_DELIMITER = ".";
42
32
  var getFlatTagValue = (tagValue) => {
@@ -0,0 +1,258 @@
1
+ import YAML from 'yaml';
2
+
3
+ // src/iac/utils/patch-utils.ts
4
+ var DEFAULT_MERGE_STRATEGY = "transpose";
5
+ var getValuePathString = (valuePathArray = []) => valuePathArray.map((p) => encodeURIComponent(p)).join("/");
6
+ var getValuePathArray = (valuePathString = "") => valuePathString.split("/").map((p) => decodeURIComponent(p));
7
+ var isConstructedFrom = (value, constructorReference) => value !== null && typeof value === "object" && "constructor" in value && value.constructor === constructorReference;
8
+ var mergeValues = (valuePathArray = [], existingValue, newValue, mergeStrategyMap = {}) => {
9
+ const valuePathString = getValuePathString(valuePathArray);
10
+ const arrayIndexWildcardValuePathString = getValuePathString(
11
+ valuePathArray.map((p) => typeof p === "number" ? "#" : p)
12
+ );
13
+ const {
14
+ [valuePathString]: {
15
+ strategy: specificKeyMergeStrategy = DEFAULT_MERGE_STRATEGY,
16
+ data: specificKeyMergeStrategyData = void 0
17
+ } = {},
18
+ [arrayIndexWildcardValuePathString]: {
19
+ strategy: arrayIndexWildcardMergeStrategy = DEFAULT_MERGE_STRATEGY,
20
+ data: arrayIndexWildcardMergeStrategyData = void 0
21
+ } = {}
22
+ } = mergeStrategyMap;
23
+ const mergeStrategy = valuePathString in mergeStrategyMap ? specificKeyMergeStrategy : arrayIndexWildcardMergeStrategy;
24
+ const mergeStrategyData = valuePathString in mergeStrategyMap ? specificKeyMergeStrategyData : arrayIndexWildcardMergeStrategyData;
25
+ let mergedValue = typeof newValue !== "undefined" ? newValue : existingValue;
26
+ if (mergeStrategy !== "replace") {
27
+ if (isConstructedFrom(existingValue, Array) && isConstructedFrom(newValue, Array)) {
28
+ if (mergeStrategy === "accumulate") {
29
+ mergedValue = [...existingValue, ...newValue];
30
+ } else if (mergeStrategy === "accumulate-unique") {
31
+ mergedValue = [
32
+ ...existingValue,
33
+ ...newValue.filter((item) => existingValue.indexOf(item) === -1)
34
+ ];
35
+ } else if (mergeStrategy === "accumulate-unique-by") {
36
+ const existingItemMap = {};
37
+ const newItemMap = {};
38
+ for (let i = 0; i < existingValue.length; i++) {
39
+ const existingItem = existingValue[i];
40
+ if (existingItem && typeof existingItem === "object") {
41
+ const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(existingItem) : existingItem[mergeStrategyData];
42
+ existingItemMap[identifier] = existingItem;
43
+ }
44
+ }
45
+ for (let j = 0; j < newValue.length; j++) {
46
+ const newItem = newValue[j];
47
+ if (newItem && typeof newItem === "object") {
48
+ const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(newItem) : newItem[mergeStrategyData];
49
+ newItemMap[identifier] = newItem;
50
+ }
51
+ }
52
+ mergedValue = Object.keys({
53
+ ...existingItemMap,
54
+ ...newItemMap
55
+ }).map(
56
+ (id, index) => mergeValues(
57
+ [...valuePathArray, index],
58
+ existingItemMap[id],
59
+ newItemMap[id],
60
+ mergeStrategyMap
61
+ )
62
+ );
63
+ } else if (mergeStrategy === "transpose") {
64
+ const fullLength = Math.max(existingValue.length, newValue.length);
65
+ mergedValue = [...new Array(fullLength)].map(
66
+ (_empty, index) => mergeValues(
67
+ [...valuePathArray, index],
68
+ existingValue[index],
69
+ newValue[index],
70
+ mergeStrategyMap
71
+ )
72
+ );
73
+ }
74
+ } else if (isConstructedFrom(existingValue, Object) && isConstructedFrom(newValue, Object)) {
75
+ mergedValue = Object.keys({ ...existingValue, ...newValue }).reduce(
76
+ (acc, k) => ({
77
+ ...acc,
78
+ [k]: mergeValues(
79
+ [...valuePathArray, k],
80
+ existingValue[k],
81
+ newValue[k],
82
+ mergeStrategyMap
83
+ )
84
+ }),
85
+ {}
86
+ );
87
+ }
88
+ }
89
+ return mergedValue;
90
+ };
91
+
92
+ // src/iac/utils/index.ts
93
+ var addParameter = (parameterInfo, template) => {
94
+ const { ParameterId, Parameter, Label, Group } = parameterInfo;
95
+ const {
96
+ Parameters,
97
+ Metadata: {
98
+ "AWS::CloudFormation::Interface": {
99
+ ParameterGroups = [],
100
+ ParameterLabels = {}
101
+ } = {}
102
+ } = {}
103
+ } = template;
104
+ let NewParameterGroups = ParameterGroups;
105
+ if (Group) {
106
+ const GroupObject = ParameterGroups.filter(
107
+ (g) => g.Label?.default === Group
108
+ )[0];
109
+ NewParameterGroups = GroupObject ? ParameterGroups.map(
110
+ (g) => g.Label?.default === Group ? {
111
+ ...g,
112
+ Parameters: [...g.Parameters || [], ParameterId]
113
+ } : g
114
+ ) : [
115
+ ...ParameterGroups,
116
+ {
117
+ Label: {
118
+ default: Group
119
+ },
120
+ Parameters: [ParameterId]
121
+ }
122
+ ];
123
+ }
124
+ return {
125
+ ...template,
126
+ Parameters: {
127
+ ...Parameters,
128
+ [ParameterId]: Parameter
129
+ },
130
+ Metadata: {
131
+ ...template.Metadata,
132
+ "AWS::CloudFormation::Interface": {
133
+ ...template?.Metadata?.["AWS::CloudFormation::Interface"],
134
+ ParameterGroups: NewParameterGroups,
135
+ ParameterLabels: {
136
+ ...ParameterLabels,
137
+ [ParameterId]: {
138
+ default: Label
139
+ }
140
+ }
141
+ }
142
+ }
143
+ };
144
+ };
145
+ var addParameters = (parameters, template) => parameters.reduce((acc, p) => addParameter(p, acc), template);
146
+ var patchTemplate = (patch, template) => mergeValues([], template, patch, {
147
+ [getValuePathString([
148
+ // Parameter Groups
149
+ "Metadata",
150
+ "AWS::CloudFormation::Interface",
151
+ "ParameterGroups"
152
+ ])]: {
153
+ strategy: "accumulate-unique-by",
154
+ data: (pG) => pG?.Label?.default
155
+ },
156
+ [getValuePathString([
157
+ // Parameter Group Parameter Ids
158
+ "Metadata",
159
+ "AWS::CloudFormation::Interface",
160
+ "ParameterGroups",
161
+ "#",
162
+ "Parameters"
163
+ ])]: {
164
+ strategy: "accumulate-unique"
165
+ }
166
+ });
167
+ var createResourcePack = (creator) => (params, template) => {
168
+ const patch = creator(params);
169
+ return patchTemplate(patch, template);
170
+ };
171
+ var SimpleCFT = class {
172
+ /**
173
+ * Create a SimpleCFT template wrapper.
174
+ *
175
+ * @param template - Initial CloudFormation template.
176
+ */
177
+ constructor(template = {
178
+ AWSTemplateFormatVersion: "2010-09-09"
179
+ }) {
180
+ this.template = template;
181
+ }
182
+ /**
183
+ * Apply a pack with configuration to the stack template.
184
+ * @see `@resistdesign/voltra/iac` and `@resistdesign/voltra/iac/packs` for examples.
185
+ * */
186
+ applyPack = (pack, params) => {
187
+ this.template = pack(params, this.template);
188
+ return this;
189
+ };
190
+ /**
191
+ * Apply a patch to the stack template.
192
+ *
193
+ * @param patch - Template patch to merge.
194
+ * */
195
+ patch = (patch) => {
196
+ this.template = patchTemplate(patch, this.template);
197
+ return this;
198
+ };
199
+ /**
200
+ * Add a stack parameter including its descriptive info and an optional parameter group.
201
+ *
202
+ * @param parameter - Parameter definition and metadata.
203
+ * */
204
+ addParameter = (parameter) => {
205
+ this.template = addParameter(parameter, this.template);
206
+ return this;
207
+ };
208
+ /**
209
+ * Add a group of stack parameters including their descriptive info and an optional parameter group.
210
+ *
211
+ * @param group - Parameter group definition.
212
+ * */
213
+ addParameterGroup = ({ Label: Group, Parameters }) => {
214
+ const parameterIds = Object.keys(Parameters);
215
+ const parameterList = parameterIds.map((ParameterId) => {
216
+ const { Label, ...Parameter } = Parameters[ParameterId];
217
+ return {
218
+ Group,
219
+ ParameterId,
220
+ Label,
221
+ Parameter
222
+ };
223
+ });
224
+ this.template = addParameters(parameterList, this.template);
225
+ return this;
226
+ };
227
+ /**
228
+ * Use a modification to dynamically apply various changes at once.
229
+ *
230
+ * @param modification - Modification callback to apply.
231
+ * */
232
+ modify = (modification) => {
233
+ modification(this);
234
+ return this;
235
+ };
236
+ /**
237
+ * Convert the stack template to a string.
238
+ *
239
+ * @returns JSON string representation of the template.
240
+ * */
241
+ toString = () => JSON.stringify(this.template, null, 2);
242
+ /**
243
+ * Convert the stack template to a JSON object.
244
+ *
245
+ * @returns Template JSON object.
246
+ * */
247
+ toJSON = () => this.template;
248
+ /**
249
+ * Convert the stack template to a YAML string.
250
+ *
251
+ * @returns YAML string representation of the template.
252
+ * */
253
+ toYAML = () => YAML.stringify(this.template, {
254
+ aliasDuplicateObjects: false
255
+ });
256
+ };
257
+
258
+ export { DEFAULT_MERGE_STRATEGY, SimpleCFT, addParameter, addParameters, createResourcePack, getValuePathArray, getValuePathString, isConstructedFrom, mergeValues, patchTemplate };
@@ -0,0 +1,71 @@
1
+ import { parseTemplate, validateAreas } from './chunk-WELZGQDJ.js';
2
+
3
+ // src/app/utils/EasyLayout.tsx
4
+ var getPascalCaseAreaName = (area) => {
5
+ return area.split("-").map((a) => a[0].toUpperCase() + a.slice(1)).join("");
6
+ };
7
+ var convertLayoutToCSS = (layout = "", spacing = {}) => {
8
+ const parsed = parseTemplate(layout);
9
+ validateAreas(parsed);
10
+ const renderTrack = (track) => {
11
+ if (track.kind === "px") {
12
+ return `${track.value}px`;
13
+ }
14
+ if (track.kind === "pct") {
15
+ return `${track.value}%`;
16
+ }
17
+ return `${track.value}fr`;
18
+ };
19
+ const areaRows = parsed.areaGrid.map((row) => row.join(" "));
20
+ const rows = parsed.rowTracks.map(renderTrack);
21
+ let css = "";
22
+ if (parsed.colTracks.length) {
23
+ css += `
24
+ grid-template-columns: ${parsed.colTracks.map(renderTrack).join(" ")};`;
25
+ }
26
+ css += `
27
+ grid-template-areas:
28
+ ${areaRows.map((a) => ` "${a}"`).join("\n")};`;
29
+ if (rows.length) {
30
+ css += `
31
+ grid-template-rows: ${rows.join(" ")};`;
32
+ }
33
+ if (typeof spacing.gap !== "undefined") {
34
+ css += `
35
+ gap: ${typeof spacing.gap === "number" ? `${spacing.gap}px` : spacing.gap};`;
36
+ }
37
+ if (typeof spacing.padding !== "undefined") {
38
+ css += `
39
+ padding: ${typeof spacing.padding === "number" ? `${spacing.padding}px` : spacing.padding};`;
40
+ }
41
+ return {
42
+ areasList: parsed.areaNames,
43
+ css
44
+ };
45
+ };
46
+ var getEasyLayoutTemplateDetails = (layout = "", spacing = {}) => convertLayoutToCSS(layout, spacing);
47
+ var createEasyLayout = (config, extendFrom, areasExtendFrom, spacing = {}) => {
48
+ return (layoutTemplate, ...expressions) => {
49
+ const mergedTemplate = layoutTemplate.reduce((acc, l, ind) => {
50
+ const expr = expressions[ind - 1];
51
+ const exprStr = typeof expr === "undefined" ? "" : expr;
52
+ return `${acc}${l}${exprStr}`;
53
+ }, "");
54
+ const { areasList, css } = convertLayoutToCSS(mergedTemplate, spacing);
55
+ const layout = config.createLayout({ base: extendFrom, css });
56
+ const areas = areasList.reduce((acc, area) => {
57
+ const pascalCaseAreaName = getPascalCaseAreaName(area);
58
+ const component = config.createArea({ base: areasExtendFrom, area });
59
+ return {
60
+ ...acc,
61
+ [pascalCaseAreaName]: component
62
+ };
63
+ }, {});
64
+ return {
65
+ layout,
66
+ areas
67
+ };
68
+ };
69
+ };
70
+
71
+ export { createEasyLayout, getEasyLayoutTemplateDetails, getPascalCaseAreaName };