funuicss 3.8.12 → 3.8.14

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.
@@ -95,7 +95,53 @@ var getAsset = function (assetName, projectData) {
95
95
  return asset || null;
96
96
  };
97
97
  /**
98
- * Interpolate values (variables and assets) in props
98
+ * Check if a value is a bucket reference and extract bucket info
99
+ */
100
+ var extractBucketInfo = function (value, props, projectData) {
101
+ if (typeof value !== 'string')
102
+ return null;
103
+ // Check if it's a bucket reference {{bucket_name}}
104
+ var bucketMatch = value.match(/^\{\{\s*([^}]+)\s*\}\}$/);
105
+ if (!bucketMatch)
106
+ return null;
107
+ var bucketReference = bucketMatch[1].trim();
108
+ // Try to get the actual bucket name from variables
109
+ var bucketName = getVariableValue(bucketReference, projectData) || bucketReference;
110
+ // Get bucketPage from props (with variable interpolation if needed)
111
+ var bucketPage = 1;
112
+ var bucketPageValue = props.bucketPage;
113
+ if (bucketPageValue !== undefined) {
114
+ if (typeof bucketPageValue === 'number') {
115
+ bucketPage = bucketPageValue;
116
+ }
117
+ else if (typeof bucketPageValue === 'string') {
118
+ // Check if bucketPage is also a variable reference
119
+ var pageVariableName = extractVariableName(bucketPageValue);
120
+ if (pageVariableName) {
121
+ var pageValue = getVariableValue(pageVariableName, projectData);
122
+ if (pageValue) {
123
+ var parsed = parseInt(pageValue, 10);
124
+ if (!isNaN(parsed) && parsed > 0) {
125
+ bucketPage = parsed;
126
+ }
127
+ }
128
+ }
129
+ else {
130
+ // Direct number string
131
+ var parsed = parseInt(bucketPageValue, 10);
132
+ if (!isNaN(parsed) && parsed > 0) {
133
+ bucketPage = parsed;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ return {
139
+ bucketName: bucketName,
140
+ bucketPage: Math.max(1, bucketPage)
141
+ };
142
+ };
143
+ /**
144
+ * Interpolate values (variables, assets, and buckets) in props
99
145
  */
100
146
  var interpolateValues = function (props, projectData) {
101
147
  if (!props || Object.keys(props).length === 0) {
@@ -133,7 +179,9 @@ var interpolateValues = function (props, projectData) {
133
179
  result[key] = variableMap[variableName];
134
180
  continue;
135
181
  }
136
- // No interpolation needed
182
+ // Check for bucket reference (treated specially in components)
183
+ // We don't interpolate bucket references here - they stay as {{bucket_name}}
184
+ // for the component to handle
137
185
  result[key] = value;
138
186
  }
139
187
  // Handle arrays - process string elements only
@@ -169,6 +217,26 @@ var interpolateValues = function (props, projectData) {
169
217
  }
170
218
  return result;
171
219
  };
220
+ /**
221
+ * Process props specifically for Store component to handle bucket references
222
+ */
223
+ var processStoreProps = function (props, projectData) {
224
+ var result = __assign({}, props);
225
+ // Check if this is a Store component and has bucket prop
226
+ if (props.bucket) {
227
+ var bucketInfo = extractBucketInfo(props.bucket, props, projectData);
228
+ if (bucketInfo) {
229
+ // Replace bucket reference with actual bucket name
230
+ result.bucket = bucketInfo.bucketName;
231
+ // Ensure bucketPage is set (override if not provided or use extracted value)
232
+ if (props.bucketPage === undefined || typeof props.bucketPage === 'string') {
233
+ result.bucketPage = bucketInfo.bucketPage;
234
+ }
235
+ console.log("Processed bucket reference: ".concat(props.bucket, " -> ").concat(bucketInfo.bucketName, ", page: ").concat(bucketInfo.bucketPage));
236
+ }
237
+ }
238
+ return result;
239
+ };
172
240
  /**
173
241
  * Universal component config getter with interpolation
174
242
  */
@@ -215,8 +283,12 @@ var getComponentConfig = function (projectData, componentName, variantName) {
215
283
  var filteredComponentProps = filterEmptyProps((variantData === null || variantData === void 0 ? void 0 : variantData.componentProps) || {});
216
284
  // Apply interpolation to component props
217
285
  var interpolatedProps = interpolateValues(filteredComponentProps, projectData);
286
+ // Special processing for Store component bucket references
287
+ var processedProps = componentName === 'Store'
288
+ ? processStoreProps(interpolatedProps, projectData)
289
+ : interpolatedProps;
218
290
  return {
219
- componentProps: interpolatedProps,
291
+ componentProps: processedProps,
220
292
  variantExists: variantExists,
221
293
  actualVariant: targetVariant,
222
294
  availableVariants: availableVariants,
@@ -227,7 +299,7 @@ exports.getComponentConfig = getComponentConfig;
227
299
  /**
228
300
  * Smart merge utility - LOCAL PROPS OVERRIDE CONFIG PROPS
229
301
  */
230
- var smartMergeWithLocalOverride = function (configProps, localProps, projectData) {
302
+ var smartMergeWithLocalOverride = function (configProps, localProps, projectData, componentName) {
231
303
  // Start with interpolated config props
232
304
  var interpolatedConfigProps = interpolateValues(configProps, projectData);
233
305
  // Simple merge: local props override config props
@@ -242,26 +314,34 @@ var smartMergeWithLocalOverride = function (configProps, localProps, projectData
242
314
  }
243
315
  }
244
316
  // Final interpolation pass to handle any variable/asset references in local props
245
- return interpolateValues(result, projectData);
317
+ var interpolatedResult = interpolateValues(result, projectData);
318
+ // Special processing for Store component bucket references
319
+ return componentName === 'Store'
320
+ ? processStoreProps(interpolatedResult, projectData)
321
+ : interpolatedResult;
246
322
  };
247
323
  /**
248
324
  * Merge component config with local props
249
325
  */
250
- var mergeComponentConfig = function (config, localProps, projectData) {
326
+ var mergeComponentConfig = function (config, localProps, projectData, componentName) {
251
327
  if (localProps === void 0) { localProps = {}; }
252
328
  // Only apply config if variant exists and has actual configuration
253
329
  var hasValidConfig = config.variantExists && Object.keys(config.componentProps).length > 0;
254
330
  if (!hasValidConfig) {
255
331
  // Still interpolate values in local props even if no config
256
332
  var interpolatedLocalProps = interpolateValues(localProps, projectData);
333
+ // Special processing for Store component
334
+ var processedLocalProps = componentName === 'Store'
335
+ ? processStoreProps(interpolatedLocalProps, projectData)
336
+ : interpolatedLocalProps;
257
337
  return {
258
- props: interpolatedLocalProps,
338
+ props: processedLocalProps,
259
339
  variant: config.actualVariant,
260
340
  hasConfig: false
261
341
  };
262
342
  }
263
343
  return {
264
- props: smartMergeWithLocalOverride(config.componentProps, localProps, projectData),
344
+ props: smartMergeWithLocalOverride(config.componentProps, localProps, projectData, componentName),
265
345
  variant: config.actualVariant,
266
346
  hasConfig: true
267
347
  };
@@ -291,15 +371,18 @@ var useComponentConfiguration = function (componentName, variantName) {
291
371
  if (localProps === void 0) { localProps = {}; }
292
372
  if (!isValidVariantName(variantName)) {
293
373
  var interpolatedLocalProps = interpolateValues(localProps, projectData);
374
+ var processedLocalProps = componentName === 'Store'
375
+ ? processStoreProps(interpolatedLocalProps, projectData)
376
+ : interpolatedLocalProps;
294
377
  return {
295
- props: interpolatedLocalProps,
378
+ props: processedLocalProps,
296
379
  variant: '',
297
380
  hasConfig: false
298
381
  };
299
382
  }
300
- return (0, exports.mergeComponentConfig)(config, localProps, projectData);
383
+ return (0, exports.mergeComponentConfig)(config, localProps, projectData, componentName);
301
384
  };
302
- }, [config, variantName, projectData]);
385
+ }, [config, variantName, projectData, componentName]);
303
386
  // Memoize getProp function
304
387
  var getProp = (0, react_1.useMemo)(function () {
305
388
  return function (propName, defaultValue) {
@@ -319,7 +402,7 @@ var useComponentProps = function (componentName, variantName, localProps) {
319
402
  var projectData = (0, theme_1.useTheme)().projectData;
320
403
  return (0, react_1.useMemo)(function () {
321
404
  var config = (0, exports.getComponentConfig)(projectData, componentName, variantName);
322
- var merged = (0, exports.mergeComponentConfig)(config, localProps, projectData);
405
+ var merged = (0, exports.mergeComponentConfig)(config, localProps, projectData, componentName);
323
406
  return merged.props;
324
407
  }, [projectData, componentName, variantName, localProps]);
325
408
  };
@@ -547,7 +630,6 @@ exports.default = {
547
630
  };
548
631
  // import { useTheme } from "../ui/theme/theme"
549
632
  // import { useMemo } from "react"
550
- // // utils/componentUtils.ts
551
633
  // // Type definitions
552
634
  // export interface ComponentProps {
553
635
  // [key: string]: any
@@ -569,6 +651,11 @@ exports.default = {
569
651
  // availableVariants: string[]
570
652
  // metadata: ComponentMetadata
571
653
  // }
654
+ // // Define the Asset interface based on your actual Asset type
655
+ // export interface Asset {
656
+ // name: string;
657
+ // url: string;
658
+ // }
572
659
  // export interface ProjectData {
573
660
  // components?: {
574
661
  // [componentName: string]: {
@@ -584,6 +671,7 @@ exports.default = {
584
671
  // updatedBy?: string;
585
672
  // updatedAt?: number;
586
673
  // }>
674
+ // assets?: Asset[] // Use the Asset interface
587
675
  // }
588
676
  // export interface MergedConfig {
589
677
  // props: ComponentProps
@@ -597,11 +685,44 @@ exports.default = {
597
685
  // isDefaultVariant: boolean
598
686
  // }
599
687
  // /**
688
+ // * Check if a variant name is valid (not empty or whitespace only)
689
+ // */
690
+ // const isValidVariantName = (variantName: string | undefined): boolean => {
691
+ // return !!variantName && variantName.trim() !== '';
692
+ // }
693
+ // /**
694
+ // * Filter out empty string and undefined values from component props
695
+ // */
696
+ // const filterEmptyProps = (props: ComponentProps): ComponentProps => {
697
+ // if (!props) return {};
698
+ // const filtered: ComponentProps = {};
699
+ // for (const key in props) {
700
+ // if (Object.prototype.hasOwnProperty.call(props, key)) {
701
+ // const value = props[key];
702
+ // // Only include props that are not undefined and not empty strings
703
+ // if (value !== undefined && value !== '') {
704
+ // filtered[key] = value;
705
+ // }
706
+ // }
707
+ // }
708
+ // return filtered;
709
+ // }
710
+ // /**
600
711
  // * Extract variable name from {{variable_name}} pattern
601
712
  // */
602
713
  // const extractVariableName = (value: string): string | null => {
603
714
  // if (typeof value !== 'string') return null;
604
- // const match = value.match(/\{\{\s*([^}]+)\s*\}\}/);
715
+ // // Match exact {{variable}} pattern
716
+ // const match = value.match(/^\{\{\s*([^}]+)\s*\}\}$/);
717
+ // return match ? match[1].trim() : null;
718
+ // }
719
+ // /**
720
+ // * Extract asset name from {{{asset_name}}} pattern
721
+ // */
722
+ // const extractAssetName = (value: string): string | null => {
723
+ // if (typeof value !== 'string') return null;
724
+ // // Match exact {{{asset}}} pattern
725
+ // const match = value.match(/^\{\{\{\s*([^}]+)\s*\}\}\}$/);
605
726
  // return match ? match[1].trim() : null;
606
727
  // }
607
728
  // /**
@@ -616,52 +737,96 @@ exports.default = {
616
737
  // return variable?.value || null;
617
738
  // }
618
739
  // /**
619
- // * SAFE Interpolate variables in props - NO RECURSION to prevent stack overflow
740
+ // * Get asset URL from project assets
741
+ // */
742
+ // const getAssetUrl = (
743
+ // assetName: string,
744
+ // projectData: ProjectData | null | undefined
745
+ // ): string | null => {
746
+ // if (!projectData?.assets || !assetName) return null;
747
+ // const asset = projectData.assets.find(a => a.name === assetName);
748
+ // return asset?.url || null;
749
+ // }
750
+ // /**
751
+ // * Get asset by name
620
752
  // */
621
- // const interpolateVariables = (
753
+ // const getAsset = (
754
+ // assetName: string,
755
+ // projectData: ProjectData | null | undefined
756
+ // ): Asset | null => {
757
+ // if (!projectData?.assets || !assetName) return null;
758
+ // const asset = projectData.assets.find(a => a.name === assetName);
759
+ // return asset || null;
760
+ // }
761
+ // /**
762
+ // * Interpolate values (variables and assets) in props
763
+ // */
764
+ // const interpolateValues = (
622
765
  // props: ComponentProps,
623
766
  // projectData: ProjectData | null | undefined
624
767
  // ): ComponentProps => {
625
- // // Quick return if no variables or empty props
626
- // if (!projectData?.variables || !props || Object.keys(props).length === 0) {
627
- // return props;
768
+ // if (!props || Object.keys(props).length === 0) {
769
+ // return props || {};
628
770
  // }
629
771
  // const result: ComponentProps = {};
630
- // // Create a lookup map for faster variable access
631
- // const variableMap = projectData.variables.reduce((acc, variable) => {
632
- // acc[variable.name] = variable.value;
633
- // return acc;
634
- // }, {} as Record<string, string>);
635
- // // Process each property safely
772
+ // // Create lookup maps for faster access
773
+ // const variableMap: Record<string, string> = {};
774
+ // const assetMap: Record<string, string> = {};
775
+ // if (projectData?.variables) {
776
+ // projectData.variables.forEach(variable => {
777
+ // variableMap[variable.name] = variable.value;
778
+ // });
779
+ // }
780
+ // if (projectData?.assets) {
781
+ // projectData.assets.forEach(asset => {
782
+ // assetMap[asset.name] = asset.url;
783
+ // });
784
+ // }
636
785
  // for (const key in props) {
637
786
  // if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
638
787
  // const value = props[key];
639
- // // Handle strings with variable interpolation
788
+ // // Handle strings with interpolation
640
789
  // if (typeof value === 'string') {
790
+ // // Check for asset reference first ({{{asset}}})
791
+ // const assetName = extractAssetName(value);
792
+ // if (assetName && assetMap[assetName]) {
793
+ // result[key] = assetMap[assetName];
794
+ // continue;
795
+ // }
796
+ // // Check for variable reference ({{variable}})
641
797
  // const variableName = extractVariableName(value);
642
798
  // if (variableName && variableMap[variableName]) {
643
799
  // result[key] = variableMap[variableName];
644
- // } else {
645
- // result[key] = value;
800
+ // continue;
646
801
  // }
802
+ // // No interpolation needed
803
+ // result[key] = value;
647
804
  // }
648
- // // Handle arrays - shallow process only
805
+ // // Handle arrays - process string elements only
649
806
  // else if (Array.isArray(value)) {
650
807
  // result[key] = value.map(item => {
651
808
  // if (typeof item === 'string') {
809
+ // // Check for asset reference
810
+ // const assetName = extractAssetName(item);
811
+ // if (assetName && assetMap[assetName]) {
812
+ // return assetMap[assetName];
813
+ // }
814
+ // // Check for variable reference
652
815
  // const variableName = extractVariableName(item);
653
- // return variableName && variableMap[variableName]
654
- // ? variableMap[variableName]
655
- // : item;
816
+ // if (variableName && variableMap[variableName]) {
817
+ // return variableMap[variableName];
818
+ // }
656
819
  // }
657
820
  // return item;
658
821
  // });
659
822
  // }
660
- // // Handle objects - ONLY shallow copy, NO deep processing
661
- // else if (value && typeof value === 'object') {
662
- // // Create a shallow copy to avoid modifying original
663
- // const shallowCopy = Array.isArray(value) ? [...value] : { ...value };
664
- // result[key] = shallowCopy;
823
+ // // Handle objects - create shallow copy (no deep interpolation)
824
+ // else if (value && typeof value === 'object' && !Array.isArray(value)) {
825
+ // result[key] = { ...value };
826
+ // }
827
+ // // Handle arrays that are objects - create shallow copy
828
+ // else if (Array.isArray(value)) {
829
+ // result[key] = [...value];
665
830
  // }
666
831
  // // All other values pass through
667
832
  // else {
@@ -671,27 +836,7 @@ exports.default = {
671
836
  // return result;
672
837
  // }
673
838
  // /**
674
- // * Check if a variant name is valid (not empty or whitespace only)
675
- // */
676
- // const isValidVariantName = (variantName: string | undefined): boolean => {
677
- // return !!variantName && variantName.trim() !== '';
678
- // }
679
- // /**
680
- // * Filter out empty string and undefined values from component props
681
- // */
682
- // const filterEmptyProps = (props: ComponentProps): ComponentProps => {
683
- // const filtered: ComponentProps = {};
684
- // for (const key in props) {
685
- // const value = props[key];
686
- // // Only include props that are not undefined and not empty strings
687
- // if (value !== undefined && value !== '') {
688
- // filtered[key] = value;
689
- // }
690
- // }
691
- // return filtered;
692
- // }
693
- // /**
694
- // * Universal component config getter with variable interpolation
839
+ // * Universal component config getter with interpolation
695
840
  // */
696
841
  // export const getComponentConfig = (
697
842
  // projectData: ProjectData | null | undefined,
@@ -706,7 +851,7 @@ exports.default = {
706
851
  // actualVariant: variantName,
707
852
  // availableVariants: [],
708
853
  // metadata: {}
709
- // }
854
+ // };
710
855
  // }
711
856
  // const component = projectData.components[componentName];
712
857
  // const availableVariants = Object.keys(component);
@@ -733,11 +878,11 @@ exports.default = {
733
878
  // }
734
879
  // const variantData = component[targetVariant];
735
880
  // // Filter out empty string and undefined props from config
736
- // let filteredComponentProps = filterEmptyProps(variantData?.componentProps || {});
737
- // // Apply variable interpolation to component props
738
- // filteredComponentProps = interpolateVariables(filteredComponentProps, projectData);
881
+ // const filteredComponentProps = filterEmptyProps(variantData?.componentProps || {});
882
+ // // Apply interpolation to component props
883
+ // const interpolatedProps = interpolateValues(filteredComponentProps, projectData);
739
884
  // return {
740
- // componentProps: filteredComponentProps,
885
+ // componentProps: interpolatedProps,
741
886
  // variantExists,
742
887
  // actualVariant: targetVariant,
743
888
  // availableVariants,
@@ -745,7 +890,7 @@ exports.default = {
745
890
  // };
746
891
  // }
747
892
  // /**
748
- // * Smart merge utility - LOCAL PROPS OVERRIDE CONFIG PROPS with variable interpolation
893
+ // * Smart merge utility - LOCAL PROPS OVERRIDE CONFIG PROPS
749
894
  // */
750
895
  // const smartMergeWithLocalOverride = (
751
896
  // configProps: ComponentProps,
@@ -753,16 +898,20 @@ exports.default = {
753
898
  // projectData: ProjectData | null | undefined
754
899
  // ): ComponentProps => {
755
900
  // // Start with interpolated config props
756
- // const interpolatedConfigProps = interpolateVariables(configProps, projectData);
757
- // const interpolatedLocalProps = interpolateVariables(localProps, projectData);
901
+ // const interpolatedConfigProps = interpolateValues(configProps, projectData);
758
902
  // // Simple merge: local props override config props
759
903
  // const result = { ...interpolatedConfigProps };
760
- // for (const key in interpolatedLocalProps) {
761
- // if (interpolatedLocalProps[key] !== undefined) {
762
- // result[key] = interpolatedLocalProps[key];
904
+ // // Apply local props (they will be interpolated in the final pass)
905
+ // for (const key in localProps) {
906
+ // if (Object.prototype.hasOwnProperty.call(localProps, key)) {
907
+ // const value = localProps[key];
908
+ // if (value !== undefined) {
909
+ // result[key] = value;
910
+ // }
763
911
  // }
764
912
  // }
765
- // return result;
913
+ // // Final interpolation pass to handle any variable/asset references in local props
914
+ // return interpolateValues(result, projectData);
766
915
  // }
767
916
  // /**
768
917
  // * Merge component config with local props
@@ -775,8 +924,8 @@ exports.default = {
775
924
  // // Only apply config if variant exists and has actual configuration
776
925
  // const hasValidConfig = config.variantExists && Object.keys(config.componentProps).length > 0;
777
926
  // if (!hasValidConfig) {
778
- // // Still interpolate variables in local props even if no config
779
- // const interpolatedLocalProps = interpolateVariables(localProps, projectData);
927
+ // // Still interpolate values in local props even if no config
928
+ // const interpolatedLocalProps = interpolateValues(localProps, projectData);
780
929
  // return {
781
930
  // props: interpolatedLocalProps,
782
931
  // variant: config.actualVariant,
@@ -814,7 +963,7 @@ exports.default = {
814
963
  // const mergeWithLocal = useMemo(() => {
815
964
  // return (localProps: ComponentProps = {}): MergedConfig => {
816
965
  // if (!isValidVariantName(variantName)) {
817
- // const interpolatedLocalProps = interpolateVariables(localProps, projectData);
966
+ // const interpolatedLocalProps = interpolateValues(localProps, projectData);
818
967
  // return {
819
968
  // props: interpolatedLocalProps,
820
969
  // variant: '',
@@ -826,8 +975,10 @@ exports.default = {
826
975
  // }, [config, variantName, projectData]);
827
976
  // // Memoize getProp function
828
977
  // const getProp = useMemo(() => {
829
- // return <T = any>(propName: string, defaultValue?: T): T =>
830
- // (config.componentProps[propName] ?? defaultValue) as T;
978
+ // return <T = any>(propName: string, defaultValue?: T): T => {
979
+ // const value = config.componentProps[propName];
980
+ // return (value !== undefined ? value : defaultValue) as T;
981
+ // };
831
982
  // }, [config.componentProps]);
832
983
  // return {
833
984
  // ...config,
@@ -883,279 +1034,179 @@ exports.default = {
883
1034
  // })) || [];
884
1035
  // }
885
1036
  // /**
886
- // * Hook to get interpolated value for a specific variable or string
1037
+ // * Get all assets from project
887
1038
  // */
888
- // export const useVariable = (value: string): string => {
1039
+ // export const getProjectAssets = (
1040
+ // projectData: ProjectData | null | undefined
1041
+ // ): Asset[] => {
1042
+ // return projectData?.assets || [];
1043
+ // }
1044
+ // /**
1045
+ // * Hook to get interpolated value for a specific variable or asset reference
1046
+ // */
1047
+ // export const useValue = (value: string): string => {
889
1048
  // const { projectData } = useTheme();
890
1049
  // return useMemo(() => {
891
1050
  // if (typeof value !== 'string') return value;
1051
+ // // Check for asset reference ({{{asset}}})
1052
+ // const assetName = extractAssetName(value);
1053
+ // if (assetName) {
1054
+ // const assetUrl = getAssetUrl(assetName, projectData);
1055
+ // return assetUrl || value;
1056
+ // }
1057
+ // // Check for variable reference ({{variable}})
892
1058
  // const variableName = extractVariableName(value);
893
- // if (!variableName) return value;
894
- // const variableValue = getVariableValue(variableName, projectData);
895
- // return variableValue || value;
1059
+ // if (variableName) {
1060
+ // const variableValue = getVariableValue(variableName, projectData);
1061
+ // return variableValue || value;
1062
+ // }
1063
+ // return value;
896
1064
  // }, [value, projectData]);
897
1065
  // }
898
- // import { useTheme } from "../ui/theme/theme"
899
- // import { useMemo } from "react"
900
- // // utils/componentUtils.ts
901
- // // Type definitions
902
- // export interface ComponentProps {
903
- // [key: string]: any
904
- // }
905
- // export interface ComponentMetadata {
906
- // createdAt?: Date
907
- // updatedAt?: Date
908
- // isCustom?: boolean
909
- // baseVariant?: string
910
- // }
911
- // export interface ComponentVariant {
912
- // componentProps: ComponentProps
913
- // metadata?: ComponentMetadata
914
- // }
915
- // export interface ComponentConfig {
916
- // componentProps: ComponentProps
917
- // variantExists: boolean
918
- // actualVariant: string
919
- // availableVariants: string[]
920
- // metadata: ComponentMetadata
921
- // }
922
- // export interface ProjectData {
923
- // components?: {
924
- // [componentName: string]: {
925
- // [variantName: string]: ComponentVariant
926
- // }
927
- // }
1066
+ // /**
1067
+ // * Hook to get a specific variable value
1068
+ // */
1069
+ // export const useVariable = (variableName: string): string | null => {
1070
+ // const { projectData } = useTheme();
1071
+ // return useMemo(() => {
1072
+ // if (!variableName || !projectData?.variables) return null;
1073
+ // const variable = projectData.variables.find(v => v.name === variableName);
1074
+ // return variable?.value || null;
1075
+ // }, [variableName, projectData]);
928
1076
  // }
929
- // export interface MergedConfig {
930
- // props: ComponentProps
931
- // variant: string
932
- // hasConfig: boolean
1077
+ // /**
1078
+ // * Hook to get a specific asset
1079
+ // */
1080
+ // export const useAsset = (assetName: string): Asset | null => {
1081
+ // const { projectData } = useTheme();
1082
+ // return useMemo(() => {
1083
+ // if (!assetName || !projectData?.assets) return null;
1084
+ // return getAsset(assetName, projectData);
1085
+ // }, [assetName, projectData]);
933
1086
  // }
934
- // export interface UseComponentConfigReturn extends ComponentConfig {
935
- // mergeWithLocal: (localProps?: ComponentProps) => MergedConfig
936
- // getProp: <T = any>(propName: string, defaultValue?: T) => T
937
- // hasVariant: boolean
938
- // isDefaultVariant: boolean
1087
+ // /**
1088
+ // * Hook to get a specific asset URL
1089
+ // */
1090
+ // export const useAssetUrl = (assetName: string): string | null => {
1091
+ // const { projectData } = useTheme();
1092
+ // return useMemo(() => {
1093
+ // if (!assetName || !projectData?.assets) return null;
1094
+ // return getAssetUrl(assetName, projectData);
1095
+ // }, [assetName, projectData]);
939
1096
  // }
940
1097
  // /**
941
- // * Check if a variant name is valid (not empty or whitespace only)
1098
+ // * Check if a value is a variable reference
942
1099
  // */
943
- // const isValidVariantName = (variantName: string | undefined): boolean => {
944
- // return !!variantName && variantName.trim() !== '';
1100
+ // export const isVariableReference = (value: any): boolean => {
1101
+ // return typeof value === 'string' && !!extractVariableName(value);
945
1102
  // }
946
1103
  // /**
947
- // * Filter out empty string and undefined values from component props
1104
+ // * Check if a value is an asset reference
948
1105
  // */
949
- // const filterEmptyProps = (props: ComponentProps): ComponentProps => {
950
- // const filtered: ComponentProps = {};
951
- // for (const key in props) {
952
- // const value = props[key];
953
- // // Only include props that are not undefined and not empty strings
954
- // if (value !== undefined && value !== '') {
955
- // filtered[key] = value;
956
- // }
957
- // }
958
- // return filtered;
1106
+ // export const isAssetReference = (value: any): boolean => {
1107
+ // return typeof value === 'string' && !!extractAssetName(value);
959
1108
  // }
960
1109
  // /**
961
- // * Universal component config getter
962
- // *
963
- // * @param projectData - The project configuration data
964
- // * @param componentName - Name of the component to get config for
965
- // * @param variantName - Name of the variant (defaults to 'default')
966
- // * @returns Component configuration with metadata
1110
+ // * Helper to convert variable/asset references for UI display
967
1111
  // */
968
- // export const getComponentConfig = (
969
- // projectData: ProjectData | null | undefined,
970
- // componentName: string,
971
- // variantName: string = 'default'
972
- // ): ComponentConfig => {
973
- // // Early return if no component exists
974
- // if (!projectData?.components?.[componentName]) {
975
- // return {
976
- // componentProps: {},
977
- // variantExists: false,
978
- // actualVariant: variantName,
979
- // availableVariants: [],
980
- // metadata: {}
981
- // }
1112
+ // export const formatReferenceForDisplay = (value: string): { type: 'variable' | 'asset' | 'custom', display: string } => {
1113
+ // if (!value || typeof value !== 'string') {
1114
+ // return { type: 'custom', display: value || '' };
982
1115
  // }
983
- // const component = projectData.components[componentName]
984
- // const availableVariants = Object.keys(component)
985
- // // Find the best variant match with fallback chain
986
- // let targetVariant = variantName
987
- // let variantExists = availableVariants.includes(variantName)
988
- // if (!variantExists) {
989
- // // Fallback priority: default → first available → none
990
- // if (availableVariants.includes('default')) {
991
- // targetVariant = 'default'
992
- // variantExists = true
993
- // } else if (availableVariants.length > 0) {
994
- // targetVariant = availableVariants[0]
995
- // variantExists = true
996
- // } else {
997
- // return {
998
- // componentProps: {},
999
- // variantExists: false,
1000
- // actualVariant: variantName,
1001
- // availableVariants: [],
1002
- // metadata: {}
1003
- // }
1004
- // }
1116
+ // const variableName = extractVariableName(value);
1117
+ // if (variableName) {
1118
+ // return { type: 'variable', display: variableName };
1005
1119
  // }
1006
- // const variantData = component[targetVariant]
1007
- // // Filter out empty string and undefined props from config
1008
- // const filteredComponentProps = filterEmptyProps(variantData?.componentProps || {})
1009
- // return {
1010
- // componentProps: filteredComponentProps,
1011
- // variantExists,
1012
- // actualVariant: targetVariant,
1013
- // availableVariants,
1014
- // metadata: variantData?.metadata || {}
1120
+ // const assetName = extractAssetName(value);
1121
+ // if (assetName) {
1122
+ // return { type: 'asset', display: assetName };
1015
1123
  // }
1124
+ // return { type: 'custom', display: value };
1016
1125
  // }
1017
1126
  // /**
1018
- // * Smart merge utility - LOCAL PROPS OVERRIDE CONFIG PROPS
1019
- // * If a prop exists in both local and config, local wins
1127
+ // * Create a variable reference string
1020
1128
  // */
1021
- // const smartMergeWithLocalOverride = (
1022
- // configProps: ComponentProps,
1023
- // localProps: ComponentProps
1024
- // ): ComponentProps => {
1025
- // const result = { ...configProps }
1026
- // // Apply local props - they override config props
1027
- // for (const key in localProps) {
1028
- // if (localProps[key] !== undefined) {
1029
- // // For objects, do smart merge but local object properties still override
1030
- // if (typeof localProps[key] === 'object' &&
1031
- // !Array.isArray(localProps[key]) &&
1032
- // localProps[key] !== null &&
1033
- // typeof configProps[key] === 'object' &&
1034
- // !Array.isArray(configProps[key]) &&
1035
- // configProps[key] !== null) {
1036
- // // Merge nested objects but local properties still win
1037
- // result[key] = { ...configProps[key], ...localProps[key] }
1038
- // } else {
1039
- // // Primitive values or arrays - local always wins
1040
- // result[key] = localProps[key]
1041
- // }
1042
- // }
1043
- // }
1044
- // return result
1129
+ // export const createVariableReference = (variableName: string): string => {
1130
+ // return `{{${variableName}}}`;
1045
1131
  // }
1046
1132
  // /**
1047
- // * Merge component config with local props - LOCAL PROPS OVERRIDE CONFIG
1048
- // *
1049
- // * @param config - Component configuration from getComponentConfig
1050
- // * @param localProps - Props passed directly to the component (OVERRIDES CONFIG)
1051
- // * @returns Merged configuration with metadata
1133
+ // * Create an asset reference string
1052
1134
  // */
1053
- // export const mergeComponentConfig = (
1054
- // config: ComponentConfig,
1055
- // localProps: ComponentProps = {}
1056
- // ): MergedConfig => {
1057
- // // Only apply config if variant exists and has actual configuration
1058
- // const hasValidConfig = config.variantExists && Object.keys(config.componentProps).length > 0
1059
- // if (!hasValidConfig) {
1060
- // return {
1061
- // props: localProps,
1062
- // variant: config.actualVariant,
1063
- // hasConfig: false
1064
- // }
1065
- // }
1066
- // // LOCAL PROPS OVERRIDE CONFIG PROPS
1067
- // return {
1068
- // props: smartMergeWithLocalOverride(config.componentProps, localProps),
1069
- // variant: config.actualVariant,
1070
- // hasConfig: true
1071
- // }
1135
+ // export const createAssetReference = (assetName: string): string => {
1136
+ // return `{{{${assetName}}}}`;
1072
1137
  // }
1073
1138
  // /**
1074
- // * Hook for easy component config usage with LOCAL PROP OVERRIDE
1075
- // * Uses useMemo to prevent unnecessary re-computation
1076
- // *
1077
- // * @param componentName - Name of the component
1078
- // * @param variantName - Optional variant name
1079
- // * @returns Configuration object with helper methods
1139
+ // * Check if a prop value needs interpolation
1080
1140
  // */
1081
- // export const useComponentConfiguration = (
1082
- // componentName: string,
1083
- // variantName?: string
1084
- // ): UseComponentConfigReturn => {
1085
- // const { projectData } = useTheme()
1086
- // // Memoize config computation - only recompute when dependencies change
1087
- // const config = useMemo(() => {
1088
- // // Check for valid variant name (not empty or whitespace only)
1089
- // if (!isValidVariantName(variantName)) {
1090
- // return {
1091
- // componentProps: {},
1092
- // variantExists: false,
1093
- // actualVariant: '',
1094
- // availableVariants: [],
1095
- // metadata: {}
1141
+ // export const needsInterpolation = (value: any): boolean => {
1142
+ // if (typeof value !== 'string') return false;
1143
+ // return isVariableReference(value) || isAssetReference(value);
1144
+ // }
1145
+ // /**
1146
+ // * Get all references (variables and assets) used in props
1147
+ // */
1148
+ // export const getUsedReferences = (
1149
+ // props: ComponentProps,
1150
+ // projectData: ProjectData | null | undefined
1151
+ // ): { variables: string[]; assets: string[] } => {
1152
+ // const variables: string[] = [];
1153
+ // const assets: string[] = [];
1154
+ // if (!props || !projectData) return { variables, assets };
1155
+ // const processValue = (value: any) => {
1156
+ // if (typeof value === 'string') {
1157
+ // const variableName = extractVariableName(value);
1158
+ // if (variableName) {
1159
+ // variables.push(variableName);
1160
+ // return;
1096
1161
  // }
1097
- // }
1098
- // return getComponentConfig(projectData, componentName, variantName!)
1099
- // }, [projectData, componentName, variantName])
1100
- // // Memoize merge function - LOCAL PROPS OVERRIDE CONFIG
1101
- // const mergeWithLocal = useMemo(() => {
1102
- // return (localProps: ComponentProps = {}): MergedConfig => {
1103
- // // If no valid variant name was provided, return local props as-is
1104
- // if (!isValidVariantName(variantName)) {
1105
- // return {
1106
- // props: localProps,
1107
- // variant: '',
1108
- // hasConfig: false
1109
- // }
1162
+ // const assetName = extractAssetName(value);
1163
+ // if (assetName) {
1164
+ // assets.push(assetName);
1110
1165
  // }
1111
- // return mergeComponentConfig(config, localProps)
1166
+ // } else if (Array.isArray(value)) {
1167
+ // value.forEach(processValue);
1112
1168
  // }
1113
- // }, [config, variantName])
1114
- // // Memoize getProp function (gets from config only, not merged)
1115
- // const getProp = useMemo(() => {
1116
- // return <T = any>(propName: string, defaultValue?: T): T =>
1117
- // (config.componentProps[propName] ?? defaultValue) as T
1118
- // }, [config.componentProps])
1169
+ // };
1170
+ // Object.values(props).forEach(processValue);
1119
1171
  // return {
1120
- // ...config,
1121
- // mergeWithLocal,
1122
- // getProp,
1123
- // hasVariant: config.variantExists,
1124
- // isDefaultVariant: config.actualVariant === 'default'
1125
- // }
1126
- // }
1127
- // /**
1128
- // * Hook that directly returns merged props with local override
1129
- // * Perfect for direct use in components
1130
- // */
1131
- // export const useComponentProps = (
1132
- // componentName: string,
1133
- // variantName: string = 'default',
1134
- // localProps: ComponentProps = {}
1135
- // ): ComponentProps => {
1136
- // const { projectData } = useTheme()
1137
- // return useMemo(() => {
1138
- // const config = getComponentConfig(projectData, componentName, variantName)
1139
- // const merged = mergeComponentConfig(config, localProps)
1140
- // return merged.props
1141
- // }, [projectData, componentName, variantName, localProps])
1172
+ // variables: Array.from(new Set(variables)),
1173
+ // assets: Array.from(new Set(assets))
1174
+ // };
1142
1175
  // }
1143
1176
  // /**
1144
- // * Quick utility to check if a component variant exists
1177
+ // * Get asset by name (exported version)
1145
1178
  // */
1146
- // export const hasComponentVariant = (
1147
- // projectData: ProjectData | null | undefined,
1148
- // componentName: string,
1149
- // variantName: string
1150
- // ): boolean => {
1151
- // return !!projectData?.components?.[componentName]?.[variantName]
1179
+ // export const getAssetByName = (assetName: string, projectData: ProjectData | null | undefined): Asset | null => {
1180
+ // return getAsset(assetName, projectData);
1152
1181
  // }
1153
1182
  // /**
1154
- // * Get all available variants for a component
1183
+ // * Get variable by name (exported version)
1155
1184
  // */
1156
- // export const getAvailableVariants = (
1157
- // projectData: ProjectData | null | undefined,
1158
- // componentName: string
1159
- // ): string[] => {
1160
- // return Object.keys(projectData?.components?.[componentName] || {})
1185
+ // export const getVariableByName = (variableName: string, projectData: ProjectData | null | undefined): { name: string; value: string } | null => {
1186
+ // if (!projectData?.variables || !variableName) return null;
1187
+ // const variable = projectData.variables.find(v => v.name === variableName);
1188
+ // return variable ? { name: variable.name, value: variable.value } : null;
1161
1189
  // }
1190
+ // export default {
1191
+ // getComponentConfig,
1192
+ // mergeComponentConfig,
1193
+ // useComponentConfiguration,
1194
+ // useComponentProps,
1195
+ // hasComponentVariant,
1196
+ // getAvailableVariants,
1197
+ // getProjectVariables,
1198
+ // getProjectAssets,
1199
+ // useValue,
1200
+ // useVariable,
1201
+ // useAsset,
1202
+ // useAssetUrl,
1203
+ // isVariableReference,
1204
+ // isAssetReference,
1205
+ // formatReferenceForDisplay,
1206
+ // createVariableReference,
1207
+ // createAssetReference,
1208
+ // needsInterpolation,
1209
+ // getUsedReferences,
1210
+ // getAssetByName,
1211
+ // getVariableByName
1212
+ // };