@sprlab/wccompiler 0.10.7 → 0.10.8
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.
- package/integrations/react.js +31 -18
- package/package.json +1 -1
package/integrations/react.js
CHANGED
|
@@ -841,15 +841,15 @@ export function wccReactPlugin(options = {}) {
|
|
|
841
841
|
|
|
842
842
|
|
|
843
843
|
/**
|
|
844
|
-
* Vite plugin that generates a virtual module
|
|
845
|
-
*
|
|
846
|
-
*
|
|
844
|
+
* Vite plugin that generates a virtual module with component stubs for
|
|
845
|
+
* PascalCase imports. These stubs satisfy the linter/IDE (component is "defined")
|
|
846
|
+
* and the wccReactPlugin transforms them to native custom elements at build time.
|
|
847
847
|
*
|
|
848
|
-
* This enables the
|
|
848
|
+
* This enables the standard React import pattern:
|
|
849
849
|
* import { WccCounter, WccCard } from '@wcc/react'
|
|
850
850
|
*
|
|
851
|
-
* The
|
|
852
|
-
*
|
|
851
|
+
* The stubs are zero-runtime — they're just tag name strings with slot name
|
|
852
|
+
* properties. The wccReactPlugin handles the actual JSX transformation.
|
|
853
853
|
*
|
|
854
854
|
* @param {Object} [options]
|
|
855
855
|
* @param {string} [options.moduleId='@wcc/react'] - Virtual module ID for imports
|
|
@@ -862,18 +862,25 @@ export function wccReactPlugin(options = {}) {
|
|
|
862
862
|
* import { wccReactPlugin, wccReactComponents } from '@sprlab/wccompiler/integrations/react'
|
|
863
863
|
* export default {
|
|
864
864
|
* plugins: [
|
|
865
|
+
* wccReactComponents({ componentsDir: './src/wcc' }),
|
|
865
866
|
* wccReactPlugin(),
|
|
866
|
-
*
|
|
867
|
+
* react()
|
|
867
868
|
* ]
|
|
868
869
|
* }
|
|
869
870
|
* ```
|
|
870
871
|
*
|
|
871
872
|
* @example Component.jsx
|
|
872
873
|
* ```jsx
|
|
873
|
-
* import {
|
|
874
|
+
* import { WccCard, WccList } from '@wcc/react'
|
|
874
875
|
*
|
|
875
|
-
* <
|
|
876
|
-
*
|
|
876
|
+
* <WccCard>
|
|
877
|
+
* <WccCard.Header><strong>Title</strong></WccCard.Header>
|
|
878
|
+
* <p>Body</p>
|
|
879
|
+
* </WccCard>
|
|
880
|
+
*
|
|
881
|
+
* <WccList>
|
|
882
|
+
* <WccList.Item>{(item) => <li>{item}</li>}</WccList.Item>
|
|
883
|
+
* </WccList>
|
|
877
884
|
* ```
|
|
878
885
|
*/
|
|
879
886
|
export function wccReactComponents(options = {}) {
|
|
@@ -913,7 +920,6 @@ export function wccReactComponents(options = {}) {
|
|
|
913
920
|
if (!metaMatch) continue
|
|
914
921
|
|
|
915
922
|
try {
|
|
916
|
-
// Parse the meta object (it's a JS object literal, evaluate safely)
|
|
917
923
|
const metaStr = metaMatch[1]
|
|
918
924
|
.replace(/'/g, '"')
|
|
919
925
|
.replace(/(\w+):/g, '"$1":')
|
|
@@ -934,21 +940,28 @@ export function wccReactComponents(options = {}) {
|
|
|
934
940
|
return 'export {}'
|
|
935
941
|
}
|
|
936
942
|
|
|
937
|
-
// Generate
|
|
938
|
-
|
|
943
|
+
// Generate lightweight stubs (zero runtime)
|
|
944
|
+
// The wccReactPlugin transforms these at build time
|
|
945
|
+
let code = '// Auto-generated WCC component stubs (transformed by wccReactPlugin at build time)\n'
|
|
939
946
|
|
|
940
|
-
// Import each component file to ensure registration
|
|
947
|
+
// Import each component file to ensure custom element registration
|
|
941
948
|
for (const comp of components) {
|
|
942
949
|
code += `import '${path.default.resolve(dir, comp.file)}';\n`
|
|
943
950
|
}
|
|
944
951
|
|
|
945
952
|
code += '\n'
|
|
946
953
|
|
|
947
|
-
// Generate
|
|
954
|
+
// Generate stub exports with compound slot properties
|
|
955
|
+
// Use Object.assign to create an object that holds the tag name and slot sub-properties
|
|
948
956
|
for (const comp of components) {
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
|
|
957
|
+
const slots = comp.meta.slots || []
|
|
958
|
+
code += `export const ${comp.pascalName} = Object.assign(() => '${comp.meta.tag}', { __tag: '${comp.meta.tag}'`
|
|
959
|
+
for (const slot of slots) {
|
|
960
|
+
if (!slot) continue
|
|
961
|
+
const pascalSlot = slot[0].toUpperCase() + slot.slice(1)
|
|
962
|
+
code += `, ${pascalSlot}: '${slot}'`
|
|
963
|
+
}
|
|
964
|
+
code += ` });\n`
|
|
952
965
|
}
|
|
953
966
|
|
|
954
967
|
return code
|
package/package.json
CHANGED