coralite 0.38.4 → 0.38.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"component-setup.d.ts","sourceRoot":"","sources":["../../lib/component-setup.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,mDAHG;IAAuC,GAAG,EAAlC,gBAAgB;CACxB,YA6MF;AA2FD;;;;;;;;;;;GAWG;AACH,mGAPG;IAAqB,SAAS,EAAtB,GAAG;IACe,QAAQ;IACb,aAAa,EAA1B,GAAG;IACe,aAAa;IACf,IAAI,EAApB,MAAM;CACd,GAAU,OAAO,CAAC,IAAI,CAAC,CAwCzB;sCAlWS,mBAAmB"}
1
+ {"version":3,"file":"component-setup.d.ts","sourceRoot":"","sources":["../../lib/component-setup.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,mDAHG;IAAuC,GAAG,EAAlC,gBAAgB;CACxB,YA+MF;AA2ID;;;;;;;;;;;GAWG;AACH,mGAPG;IAAqB,SAAS,EAAtB,GAAG;IACe,QAAQ;IACb,aAAa,EAA1B,GAAG;IACe,aAAa;IACf,IAAI,EAApB,MAAM;CACd,GAAU,OAAO,CAAC,IAAI,CAAC,CAwCzB;sCApZS,mBAAmB"}
package/dist/lib/index.js CHANGED
@@ -2300,7 +2300,7 @@ function findAndExtractScript(code) {
2300
2300
  }
2301
2301
  return result;
2302
2302
  }
2303
- function findAndExtractProperties(code) {
2303
+ function extractComponentProperty(code, propertyName) {
2304
2304
  const ast = getAST(code, true);
2305
2305
  let result = null;
2306
2306
  walkJS(ast, {
@@ -2308,11 +2308,11 @@ function findAndExtractProperties(code) {
2308
2308
  if (node.callee && node.callee.type === "Identifier" && node.callee.name === "defineComponent") {
2309
2309
  const firstArg = node.arguments[0];
2310
2310
  if (firstArg && firstArg.type === "ObjectExpression") {
2311
- const stateProp = firstArg.properties.find(
2312
- (prop) => prop.type === "Property" && prop.key && prop.key.type === "Identifier" && prop.key.name === "server"
2311
+ const prop = firstArg.properties.find(
2312
+ (p) => p.type === "Property" && p.key && p.key.type === "Identifier" && p.key.name === propertyName
2313
2313
  );
2314
- if (stateProp && stateProp.type === "Property") {
2315
- const { value, method } = stateProp;
2314
+ if (prop && prop.type === "Property") {
2315
+ const { value, method } = prop;
2316
2316
  let startLine = value.loc.start.line - 1;
2317
2317
  let prefix = "";
2318
2318
  let content = "";
@@ -2323,15 +2323,22 @@ function findAndExtractProperties(code) {
2323
2323
  } else if (value.type === "FunctionExpression") {
2324
2324
  if (method) {
2325
2325
  const isAsync = value.async;
2326
- prefix += (isAsync ? "async " : "") + "function server";
2326
+ prefix += (isAsync ? "async " : "") + "function " + propertyName;
2327
2327
  content = prefix + source;
2328
- startLine = stateProp.key.loc.start.line - 1;
2328
+ startLine = prop.key.loc.start.line - 1;
2329
2329
  } else {
2330
2330
  content = prefix + source;
2331
2331
  startLine = value.loc.start.line - 1;
2332
2332
  }
2333
2333
  } else if (value.type === "ObjectExpression") {
2334
- content = `() => (${source})`;
2334
+ if (propertyName === "server") {
2335
+ content = `() => (${source})`;
2336
+ } else {
2337
+ content = source;
2338
+ }
2339
+ startLine = value.loc.start.line - 1;
2340
+ } else if (value.type === "Literal" || value.type === "Identifier") {
2341
+ content = source;
2335
2342
  startLine = value.loc.start.line - 1;
2336
2343
  }
2337
2344
  result = {
@@ -2750,7 +2757,11 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
2750
2757
  const defaults = serialize(normalizedDefaults);
2751
2758
  const attributes = serialize(sharedFn.script?.attributes || {});
2752
2759
  const hydrationMap = serialize(generateHydrationMap(sharedFn.templateAST, sharedFn.templateValues));
2753
- const getters = serialize(sharedFn.getters || sharedFn.script?.getters || {});
2760
+ let normalizedGetters = sharedFn.getters || sharedFn.script?.getters || {};
2761
+ if (normalizedGetters) {
2762
+ normalizedGetters = normalizeObjectFunctions(normalizedGetters, astTransformer);
2763
+ }
2764
+ const getters = serialize(normalizedGetters);
2754
2765
  const dependencies = JSON.stringify(sharedFn.components || []);
2755
2766
  let normalizedSlots = sharedFn.slots || {};
2756
2767
  if (sharedFn.slots) {
@@ -4067,8 +4078,9 @@ function createComponentDefinition({ app }) {
4067
4078
  const serializableAttributes = {};
4068
4079
  if (attributes) {
4069
4080
  for (const [key, schema] of Object.entries(attributes)) {
4081
+ const type = schema.type || schema;
4070
4082
  serializableAttributes[key] = {
4071
- type: schema.type.name || schema.type,
4083
+ type: type.name || type,
4072
4084
  default: schema.default
4073
4085
  };
4074
4086
  }
@@ -4090,7 +4102,8 @@ function createComponentDefinition({ app }) {
4090
4102
  };
4091
4103
  if (attributes) {
4092
4104
  for (const [key, schema] of Object.entries(attributes)) {
4093
- const typeName = schema.type.name || schema.type;
4105
+ const type = schema.type || schema;
4106
+ const typeName = type.name || type;
4094
4107
  if (state[key] !== void 0) {
4095
4108
  const value = state[key];
4096
4109
  if (typeName === "Number") {
@@ -4260,13 +4273,51 @@ async function _safeRegister(component, scriptManager, scriptResultMeta = null)
4260
4273
  extractedComponents = extractedClient.components || [];
4261
4274
  }
4262
4275
  if (!component._extractedServer) {
4263
- component._extractedServer = findAndExtractProperties(component.script);
4276
+ component._extractedServer = extractComponentProperty(component.script, "server");
4264
4277
  }
4265
4278
  const extractedServer = component._extractedServer;
4266
4279
  if (extractedServer) {
4267
4280
  scriptObj.stateContent = extractedServer.content;
4268
4281
  scriptObj.stateLineOffset = (component.lineOffset || 0) + extractedServer.lineOffset;
4269
4282
  }
4283
+ if (!scriptResultMeta) {
4284
+ const extractedGetters = extractComponentProperty(component.script, "getters");
4285
+ if (extractedGetters) {
4286
+ try {
4287
+ if (extractedGetters.content.trim().startsWith("{")) {
4288
+ scriptObj.getters = new Function(`return ${extractedGetters.content}`)();
4289
+ }
4290
+ } catch {
4291
+ }
4292
+ }
4293
+ const extractedAttributes = extractComponentProperty(component.script, "attributes");
4294
+ if (extractedAttributes) {
4295
+ try {
4296
+ if (extractedAttributes.content.trim().startsWith("{")) {
4297
+ const attrs = new Function(`return ${extractedAttributes.content}`)();
4298
+ const serializableAttributes = {};
4299
+ for (const [key, schema] of Object.entries(attrs)) {
4300
+ const type = schema.type || schema;
4301
+ serializableAttributes[key] = {
4302
+ type: type.name || type,
4303
+ default: schema.default
4304
+ };
4305
+ }
4306
+ scriptObj.attributes = serializableAttributes;
4307
+ }
4308
+ } catch {
4309
+ }
4310
+ }
4311
+ const extractedSlots = extractComponentProperty(component.script, "slots");
4312
+ if (extractedSlots) {
4313
+ try {
4314
+ if (extractedSlots.content.trim().startsWith("{")) {
4315
+ scriptObj.slots = new Function(`return ${extractedSlots.content}`)();
4316
+ }
4317
+ } catch {
4318
+ }
4319
+ }
4320
+ }
4270
4321
  }
4271
4322
  const declarativeComponents = (component.customElements || []).map((el) => el.name);
4272
4323
  const nestedComponents = [.../* @__PURE__ */ new Set([...declarativeComponents, ...extractedComponents])];
@@ -5286,7 +5337,7 @@ function createRenderer({
5286
5337
  extractedComponents = extractedScript.components || [];
5287
5338
  }
5288
5339
  if (!moduleComponent.result._extractedProperties) {
5289
- moduleComponent.result._extractedProperties = findAndExtractProperties(module.script);
5340
+ moduleComponent.result._extractedProperties = extractComponentProperty(module.script, "server");
5290
5341
  }
5291
5342
  const extractedProperties = moduleComponent.result._extractedProperties;
5292
5343
  if (extractedProperties) {
@@ -5830,6 +5881,44 @@ function createRenderer({
5830
5881
  mappedSessionObject,
5831
5882
  pageContext
5832
5883
  });
5884
+ const componentsToInclude = /* @__PURE__ */ new Set();
5885
+ const addComponentAndDependencies2 = (id) => {
5886
+ if (componentsToInclude.has(id)) {
5887
+ return;
5888
+ }
5889
+ componentsToInclude.add(id);
5890
+ const sharedFn = scriptManager.sharedFunctions[id];
5891
+ if (sharedFn && sharedFn.components) {
5892
+ const components = sharedFn.components;
5893
+ for (let i = 0; i < components.length; i++) {
5894
+ addComponentAndDependencies2(components[i]);
5895
+ }
5896
+ }
5897
+ };
5898
+ for (const tag of mappedSessionObject.componentTags) {
5899
+ addComponentAndDependencies2(tag);
5900
+ }
5901
+ if (mappedSessionObject.scripts.content[mappedComponent.path.pathname]) {
5902
+ const scripts = mappedSessionObject.scripts.content[mappedComponent.path.pathname];
5903
+ for (const instanceId in scripts) {
5904
+ const script = scripts[instanceId];
5905
+ addComponentAndDependencies2(script.componentId);
5906
+ if (script.components) {
5907
+ const components = script.components;
5908
+ for (let i = 0; i < components.length; i++) {
5909
+ addComponentAndDependencies2(components[i]);
5910
+ }
5911
+ }
5912
+ }
5913
+ }
5914
+ for (const module of scriptManager.scriptModules) {
5915
+ const extractedComponents = module.client?._extractedComponents || module._extractedComponents;
5916
+ if (extractedComponents) {
5917
+ for (const tag of extractedComponents) {
5918
+ addComponentAndDependencies2(tag);
5919
+ }
5920
+ }
5921
+ }
5833
5922
  const { head: headElement, body: bodyElement } = findHeadAndBody(mappedComponent.root);
5834
5923
  if (normalizedOptions.externalStyles && normalizedOptions.externalStyles.length > 0) {
5835
5924
  injectExternalStyles(mappedComponent.root, headElement, normalizedOptions.externalStyles);
@@ -5857,7 +5946,7 @@ function createRenderer({
5857
5946
  injectStyles(mappedComponent.root, headElement, mappedSessionObject.styles);
5858
5947
  }
5859
5948
  }
5860
- if (mappedSessionObject.componentTags.size > 0) {
5949
+ if (componentsToInclude.size > 0) {
5861
5950
  const targetElement = headElement || bodyElement || mappedComponent.root;
5862
5951
  const layoutStyleElement = createCoraliteElement({
5863
5952
  type: "tag",
@@ -5866,7 +5955,7 @@ function createRenderer({
5866
5955
  attribs: { id: "coralite-components" },
5867
5956
  children: []
5868
5957
  });
5869
- const selectors = Array.from(mappedSessionObject.componentTags);
5958
+ const selectors = Array.from(componentsToInclude);
5870
5959
  selectors.push("c-token");
5871
5960
  layoutStyleElement.children.push(createCoraliteTextNode({
5872
5961
  type: "text",
@@ -5902,44 +5991,6 @@ function createRenderer({
5902
5991
  });
5903
5992
  }
5904
5993
  const chunkManifest = {};
5905
- const componentsToInclude = /* @__PURE__ */ new Set();
5906
- const addComponentAndDependencies2 = (id) => {
5907
- if (componentsToInclude.has(id)) {
5908
- return;
5909
- }
5910
- componentsToInclude.add(id);
5911
- const sharedFn = scriptManager.sharedFunctions[id];
5912
- if (sharedFn && sharedFn.components) {
5913
- const components = sharedFn.components;
5914
- for (let i = 0; i < components.length; i++) {
5915
- addComponentAndDependencies2(components[i]);
5916
- }
5917
- }
5918
- };
5919
- for (const instanceId in scripts) {
5920
- const script = scripts[instanceId];
5921
- addComponentAndDependencies2(script.componentId);
5922
- if (script.components) {
5923
- const components = script.components;
5924
- for (let i = 0; i < components.length; i++) {
5925
- addComponentAndDependencies2(components[i]);
5926
- }
5927
- }
5928
- }
5929
- for (const tag of declarativeTags) {
5930
- addComponentAndDependencies2(tag);
5931
- }
5932
- for (const module of scriptManager.scriptModules) {
5933
- if (module.client?._extractedComponents) {
5934
- for (const tag of module.client._extractedComponents) {
5935
- addComponentAndDependencies2(tag);
5936
- }
5937
- } else if (module._extractedComponents) {
5938
- for (const tag of module._extractedComponents) {
5939
- addComponentAndDependencies2(tag);
5940
- }
5941
- }
5942
- }
5943
5994
  for (const tag of componentsToInclude) {
5944
5995
  if (scriptResult.manifest[tag]) {
5945
5996
  chunkManifest[tag] = scriptResult.manifest[tag];
@@ -6782,9 +6833,9 @@ export {
6782
6833
  definePlugin,
6783
6834
  discoverHtmlFiles,
6784
6835
  enhanceNode,
6836
+ extractComponentProperty,
6785
6837
  extractGlobals,
6786
6838
  findAndExtractImperativeComponents,
6787
- findAndExtractProperties,
6788
6839
  findAndExtractScript,
6789
6840
  findHeadAndBody,
6790
6841
  generateHydrationMap,