coralite 0.31.1 → 0.31.3
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/dist/lib/coralite.d.ts.map +1 -1
- package/dist/lib/index.js +84 -27
- package/dist/lib/index.js.map +2 -2
- package/dist/lib/script-manager.d.ts +5 -1
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/plugins/define-component.d.ts +2 -2
- package/dist/plugins/define-component.d.ts.map +1 -1
- package/dist/plugins/define-component.js +29 -19
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/module.d.ts +2 -0
- package/dist/types/module.d.ts.map +1 -1
- package/dist/types/script.d.ts +6 -0
- package/dist/types/script.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,2IAXW,cAAc,QAmMxB;;IA3ND;;;;;;;;;;;;;;;;OAgBG;IAEH;;OAEG;IAEH;;;;;;;;;;;;OAYG;IACH,8HAXW,cAAc,EAmMxB;IA1JC,6DAA+B;IAG/B;;;;;;;;;;;;;;MAWC;IAED,oDAAoD;IACpD,eADW,GAAG,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAAC,CAClB;IAG9B;;;;;;;;;;;;;;MAcC;IAGD,8BAAqD;IAGrD;;;;;;;;
|
|
1
|
+
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,2IAXW,cAAc,QAmMxB;;IA3ND;;;;;;;;;;;;;;;;OAgBG;IAEH;;OAEG;IAEH;;;;;;;;;;;;OAYG;IACH,8HAXW,cAAc,E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,qBAAqB;6BAHT,WAAW;4BAAX,WAAW;+BACiB,YAAY;2CAiCzD,mBAAmB;qCAAnB,mBAAmB;0CAIL,gBAAgB;+BAvBxB,iBAAiB;oCAmBvB,mBAAmB;uCAAnB,mBAAmB;0CAAnB,mBAAmB;qCAAnB,mBAAmB;oCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -9462,7 +9462,7 @@ ScriptManager.prototype.getHelpers = function() {
|
|
|
9462
9462
|
}
|
|
9463
9463
|
return `{${helpers}}`;
|
|
9464
9464
|
};
|
|
9465
|
-
ScriptManager.prototype.registerComponent = function({ id, script = {}, filePath, templateAST = null, templateValues = null, defaultValues = {}, styles = "" }) {
|
|
9465
|
+
ScriptManager.prototype.registerComponent = function({ id, script = {}, filePath, templateAST = null, templateValues = null, defaultValues = {}, styles = "", slots = {} }) {
|
|
9466
9466
|
this.sharedFunctions[id] = {
|
|
9467
9467
|
id,
|
|
9468
9468
|
script,
|
|
@@ -9470,6 +9470,7 @@ ScriptManager.prototype.registerComponent = function({ id, script = {}, filePath
|
|
|
9470
9470
|
templateValues,
|
|
9471
9471
|
defaultValues,
|
|
9472
9472
|
styles,
|
|
9473
|
+
slots,
|
|
9473
9474
|
imports: script.imports || [],
|
|
9474
9475
|
components: script.components || [],
|
|
9475
9476
|
filePath: filePath ? resolve(filePath) : `/component-${id}.js`
|
|
@@ -9709,6 +9710,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9709
9710
|
const styles = JSON.stringify(this.sharedFunctions[componentId].styles || "");
|
|
9710
9711
|
const defaults = serialize(this.sharedFunctions[componentId].defaultValues || {});
|
|
9711
9712
|
const dependencies = JSON.stringify(this.sharedFunctions[componentId].components || []);
|
|
9713
|
+
const slots = serialize(this.sharedFunctions[componentId].slots || {});
|
|
9712
9714
|
componentEntryCode += `
|
|
9713
9715
|
export default {
|
|
9714
9716
|
componentId: "${componentId}",
|
|
@@ -9716,6 +9718,7 @@ export default {
|
|
|
9716
9718
|
templateValues: ${templateValues},
|
|
9717
9719
|
styles: ${styles},
|
|
9718
9720
|
defaultValues: (() => { const defaults = ${defaults}; return defaults; })(),
|
|
9721
|
+
slots: (() => { const slots = ${slots}; return slots; })(),
|
|
9719
9722
|
dependencies: ${dependencies},
|
|
9720
9723
|
imports: ${hasImports ? "componentImports" : "{}"},
|
|
9721
9724
|
script: componentScript
|
|
@@ -10071,10 +10074,10 @@ var defineComponent = createPlugin({
|
|
|
10071
10074
|
* It is used to register components with their associated tokens and slots.
|
|
10072
10075
|
*
|
|
10073
10076
|
* @param {Object} options - Configuration options for the component
|
|
10074
|
-
* @param {Object.<string, (string |
|
|
10077
|
+
* @param {Object.<string, (string | CoraliteModuleTokenFunction)>} [options.tokens] -
|
|
10075
10078
|
* Computed tokens that will be available in the template. These can be
|
|
10076
10079
|
* strings or functions that return values.
|
|
10077
|
-
* @param {Object.<string,
|
|
10080
|
+
* @param {Object.<string, CoraliteModuleSlotFunction>} [options.slots] -
|
|
10078
10081
|
* Computed slots for the component. These are functions that define
|
|
10079
10082
|
* how content should be rendered within the component.
|
|
10080
10083
|
* @param {Object} [options.client] - Client side configuration.
|
|
@@ -10096,9 +10099,16 @@ var defineComponent = createPlugin({
|
|
|
10096
10099
|
element
|
|
10097
10100
|
} = context;
|
|
10098
10101
|
let results = { ...values };
|
|
10102
|
+
results.__script__ = {
|
|
10103
|
+
values: {},
|
|
10104
|
+
components: client?.components || [],
|
|
10105
|
+
defaultValues: {},
|
|
10106
|
+
slots: slots || {}
|
|
10107
|
+
};
|
|
10099
10108
|
if (client && client.setup) {
|
|
10100
10109
|
const initialValues = await client.setup(results);
|
|
10101
10110
|
results = Object.assign(results, initialValues);
|
|
10111
|
+
Object.assign(results.__script__.defaultValues, initialValues);
|
|
10102
10112
|
}
|
|
10103
10113
|
if (typeof tokens === "object" && tokens !== null) {
|
|
10104
10114
|
for (const key in tokens) {
|
|
@@ -10106,7 +10116,10 @@ var defineComponent = createPlugin({
|
|
|
10106
10116
|
const token = tokens[key];
|
|
10107
10117
|
let result = token;
|
|
10108
10118
|
if (typeof token === "function") {
|
|
10119
|
+
results.__script__.defaultValues[key] = token;
|
|
10109
10120
|
result = await token(results);
|
|
10121
|
+
} else {
|
|
10122
|
+
results.__script__.defaultValues[key] = token;
|
|
10110
10123
|
}
|
|
10111
10124
|
if (result) {
|
|
10112
10125
|
results[key] = await processTokenValue(result, {
|
|
@@ -10174,24 +10187,24 @@ var defineComponent = createPlugin({
|
|
|
10174
10187
|
}
|
|
10175
10188
|
}
|
|
10176
10189
|
}
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10190
|
+
const hasScript = client && typeof client.script === "function";
|
|
10191
|
+
const hasSetup = client && typeof client.setup === "function";
|
|
10192
|
+
const hasComponents = client && client.components && client.components.length > 0;
|
|
10193
|
+
const hasTokens = typeof tokens === "object" && tokens !== null && Object.keys(tokens).length > 0;
|
|
10194
|
+
if (hasScript || hasSetup || hasComponents || hasTokens) {
|
|
10195
|
+
if (hasScript) {
|
|
10196
|
+
const scriptTextContent = client.script.toString().trim();
|
|
10197
|
+
const args = {};
|
|
10198
|
+
for (const key in results) {
|
|
10199
|
+
if (!Object.hasOwn(results, key)) continue;
|
|
10200
|
+
if (scriptTextContent.includes(key)) {
|
|
10201
|
+
args[key] = results[key];
|
|
10202
|
+
}
|
|
10203
|
+
}
|
|
10204
|
+
results.__script__.values = args;
|
|
10205
|
+
if (client.imports) {
|
|
10206
|
+
results.__script__.imports = client.imports;
|
|
10184
10207
|
}
|
|
10185
|
-
}
|
|
10186
|
-
results.__script__ = {
|
|
10187
|
-
values: args,
|
|
10188
|
-
components: client.components || []
|
|
10189
|
-
};
|
|
10190
|
-
if (typeof client.setup === "function") {
|
|
10191
|
-
results.__script__.defaultValues = await client.setup(results) || {};
|
|
10192
|
-
}
|
|
10193
|
-
if (client.imports) {
|
|
10194
|
-
results.__script__.imports = client.imports;
|
|
10195
10208
|
}
|
|
10196
10209
|
} else {
|
|
10197
10210
|
delete results.__script__;
|
|
@@ -11141,8 +11154,8 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11141
11154
|
this.componentId = module.default.componentId;
|
|
11142
11155
|
this._abortController = null;
|
|
11143
11156
|
|
|
11144
|
-
|
|
11145
|
-
this._instanceId = \`\${this.componentId}-\${
|
|
11157
|
+
this._index = typeof crypto !== 'undefined' && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15);
|
|
11158
|
+
this._instanceId = \`\${this.componentId}-\${this._index}\`;
|
|
11146
11159
|
|
|
11147
11160
|
this._values = {};
|
|
11148
11161
|
|
|
@@ -11337,7 +11350,18 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11337
11350
|
for (let i = 0; i < slots.length; i++) {
|
|
11338
11351
|
const slot = slots[i];
|
|
11339
11352
|
const slotName = slot.getAttribute('name') || 'default';
|
|
11340
|
-
|
|
11353
|
+
let projectedNodes = this._lightDomSlots[slotName];
|
|
11354
|
+
|
|
11355
|
+
if (module.default.slots && typeof module.default.slots[slotName] === 'function') {
|
|
11356
|
+
const computedResult = module.default.slots[slotName](projectedNodes || [], this._values);
|
|
11357
|
+
if (typeof computedResult === 'string') {
|
|
11358
|
+
const tempDiv = document.createElement('div');
|
|
11359
|
+
tempDiv.innerHTML = computedResult;
|
|
11360
|
+
projectedNodes = Array.from(tempDiv.childNodes);
|
|
11361
|
+
} else if (Array.isArray(computedResult)) {
|
|
11362
|
+
projectedNodes = computedResult;
|
|
11363
|
+
}
|
|
11364
|
+
}
|
|
11341
11365
|
|
|
11342
11366
|
if (projectedNodes && projectedNodes.length > 0) {
|
|
11343
11367
|
// We have content to project, clear the fallback content
|
|
@@ -11360,9 +11384,22 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11360
11384
|
const refElements = this.querySelectorAll('[ref]');
|
|
11361
11385
|
for (let i = 0; i < refElements.length; i++) {
|
|
11362
11386
|
const element = refElements[i];
|
|
11387
|
+
|
|
11388
|
+
let current = element.parentNode;
|
|
11389
|
+
let isNested = false;
|
|
11390
|
+
while (current && current !== this) {
|
|
11391
|
+
if (current.tagName && current.tagName.includes('-')) {
|
|
11392
|
+
isNested = true;
|
|
11393
|
+
break;
|
|
11394
|
+
}
|
|
11395
|
+
current = current.parentNode;
|
|
11396
|
+
}
|
|
11397
|
+
|
|
11398
|
+
if (isNested) continue;
|
|
11399
|
+
|
|
11363
11400
|
const refName = element.getAttribute('ref');
|
|
11364
11401
|
|
|
11365
|
-
const dynamicId = \`\${this.componentId}__\${refName}-\${this.
|
|
11402
|
+
const dynamicId = \`\${this.componentId}__\${refName}-\${this._index}\`;
|
|
11366
11403
|
element.setAttribute('ref', dynamicId);
|
|
11367
11404
|
|
|
11368
11405
|
this._values[\`ref_\${refName}\`] = dynamicId;
|
|
@@ -11713,6 +11750,24 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
|
|
|
11713
11750
|
nestedComponents = Array.from(/* @__PURE__ */ new Set([...declarativeComponents]));
|
|
11714
11751
|
scriptObj.components = nestedComponents;
|
|
11715
11752
|
}
|
|
11753
|
+
const componentTokens = {};
|
|
11754
|
+
for (let i = 0; i < module.values.attributes.length; i++) {
|
|
11755
|
+
const item = module.values.attributes[i];
|
|
11756
|
+
for (let j = 0; j < item.tokens.length; j++) {
|
|
11757
|
+
componentTokens[item.tokens[j].name] = true;
|
|
11758
|
+
}
|
|
11759
|
+
}
|
|
11760
|
+
for (let i = 0; i < module.values.textNodes.length; i++) {
|
|
11761
|
+
const item = module.values.textNodes[i];
|
|
11762
|
+
for (let j = 0; j < item.tokens.length; j++) {
|
|
11763
|
+
componentTokens[item.tokens[j].name] = true;
|
|
11764
|
+
}
|
|
11765
|
+
}
|
|
11766
|
+
for (const token of Object.keys(componentTokens)) {
|
|
11767
|
+
if (defaultValues[token] === void 0 && scriptResult[token] !== void 0) {
|
|
11768
|
+
defaultValues[token] = scriptResult[token];
|
|
11769
|
+
}
|
|
11770
|
+
}
|
|
11716
11771
|
this._scriptManager.registerComponent({
|
|
11717
11772
|
id: module.id,
|
|
11718
11773
|
script: scriptObj,
|
|
@@ -11720,7 +11775,8 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
|
|
|
11720
11775
|
templateAST,
|
|
11721
11776
|
templateValues,
|
|
11722
11777
|
defaultValues,
|
|
11723
|
-
styles: stylesHTML
|
|
11778
|
+
styles: stylesHTML,
|
|
11779
|
+
slots: scriptResult.__script__?.slots || {}
|
|
11724
11780
|
});
|
|
11725
11781
|
if (nestedComponents.length > 0) {
|
|
11726
11782
|
await this._processDependentComponents(nestedComponents, renderContext, parentComponent);
|
|
@@ -11813,7 +11869,7 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
11813
11869
|
const componentDefaultValues = scriptResult.__script__.defaultValues || {};
|
|
11814
11870
|
if (values) {
|
|
11815
11871
|
for (const token of Object.keys(componentTokens)) {
|
|
11816
|
-
if (
|
|
11872
|
+
if (componentDefaultValues[token] === void 0 && values[token] !== void 0) {
|
|
11817
11873
|
componentDefaultValues[token] = values[token];
|
|
11818
11874
|
}
|
|
11819
11875
|
}
|
|
@@ -11831,7 +11887,8 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
11831
11887
|
templateAST,
|
|
11832
11888
|
templateValues,
|
|
11833
11889
|
defaultValues: componentDefaultValues,
|
|
11834
|
-
styles: stylesHTML
|
|
11890
|
+
styles: stylesHTML,
|
|
11891
|
+
slots: scriptResult.__script__.slots || {}
|
|
11835
11892
|
});
|
|
11836
11893
|
if (mergedComponents.length > 0) {
|
|
11837
11894
|
await this._processDependentComponents(mergedComponents, renderContext, component);
|