@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.
@@ -841,15 +841,15 @@ export function wccReactPlugin(options = {}) {
841
841
 
842
842
 
843
843
  /**
844
- * Vite plugin that generates a virtual module `@wcc/react` (or custom id)
845
- * exporting pre-built React wrapper components for all WCC components found
846
- * in the project's compiled output directory.
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 ideal import experience:
848
+ * This enables the standard React import pattern:
849
849
  * import { WccCounter, WccCard } from '@wcc/react'
850
850
  *
851
- * The plugin scans the output directory for compiled .js files, reads their
852
- * `static __meta` declarations, and generates wrapper code using createWccWrapper.
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
- * wccReactComponents({ componentsDir: './src/wcc' })
867
+ * react()
867
868
  * ]
868
869
  * }
869
870
  * ```
870
871
  *
871
872
  * @example Component.jsx
872
873
  * ```jsx
873
- * import { WccCounter, WccCard } from '@wcc/react'
874
+ * import { WccCard, WccList } from '@wcc/react'
874
875
  *
875
- * <WccCounter count={count} onCountChange={setCount} />
876
- * <WccCard><div slot="header">Title</div></WccCard>
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 the virtual module code
938
- let code = `import { createWccWrapper } from '@sprlab/wccompiler/adapters/react';\n`
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 wrapper exports
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 eventsArr = JSON.stringify(comp.meta.events || [])
950
- const modelsArr = JSON.stringify(comp.meta.models || [])
951
- code += `export const ${comp.pascalName} = createWccWrapper('${comp.meta.tag}', { events: ${eventsArr}, models: ${modelsArr} });\n`
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
5
  "type": "module",
6
6
  "exports": {