coralite 0.31.2 → 0.31.4
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 +222 -53
- package/dist/lib/index.js.map +2 -2
- package/dist/lib/parse.d.ts.map +1 -1
- package/dist/lib/script-manager.d.ts +5 -1
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +22 -0
- package/dist/lib/utils.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 +40 -26
- package/dist/plugins/metadata.d.ts.map +1 -1
- package/dist/plugins/metadata.js +7 -1
- 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;AA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BAAmB,GAAC,eAAe,GAAC,cAAc,4BAapL;;;wCAzvCU,cAAc,KACZ,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;oCA5qCN,mBAAmB;4CAAnB,mBAAmB;8BA/Bd,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
|
@@ -6447,6 +6447,39 @@ function cleanKeys(object) {
|
|
|
6447
6447
|
}
|
|
6448
6448
|
return result;
|
|
6449
6449
|
}
|
|
6450
|
+
function normalizeObjectFunctions(target) {
|
|
6451
|
+
if (Array.isArray(target)) {
|
|
6452
|
+
target.forEach(normalizeObjectFunctions);
|
|
6453
|
+
} else if (typeof target === "object" && target !== null) {
|
|
6454
|
+
for (const key in target) {
|
|
6455
|
+
if (typeof target[key] === "function") {
|
|
6456
|
+
if (target[key].__normalized) continue;
|
|
6457
|
+
const normalizedString = normalizeFunction(target[key]);
|
|
6458
|
+
const originalFunction = target[key];
|
|
6459
|
+
target[key] = function() {
|
|
6460
|
+
return originalFunction.apply(this, arguments);
|
|
6461
|
+
};
|
|
6462
|
+
target[key].toString = () => normalizedString;
|
|
6463
|
+
target[key].__normalized = true;
|
|
6464
|
+
} else {
|
|
6465
|
+
normalizeObjectFunctions(target[key]);
|
|
6466
|
+
}
|
|
6467
|
+
}
|
|
6468
|
+
}
|
|
6469
|
+
}
|
|
6470
|
+
function hasObjectKeys(obj) {
|
|
6471
|
+
return obj && typeof obj === "object" && Object.keys(obj).length > 0;
|
|
6472
|
+
}
|
|
6473
|
+
function mergeUniqueObjects(arr1, arr2) {
|
|
6474
|
+
const all = [...arr1 || [], ...arr2 || []];
|
|
6475
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6476
|
+
return all.filter((item) => {
|
|
6477
|
+
const key = typeof item === "object" ? JSON.stringify(item) : item;
|
|
6478
|
+
if (seen.has(key)) return false;
|
|
6479
|
+
seen.add(key);
|
|
6480
|
+
return true;
|
|
6481
|
+
});
|
|
6482
|
+
}
|
|
6450
6483
|
function normalizeFunction(func) {
|
|
6451
6484
|
const original = func.toString().trim();
|
|
6452
6485
|
const firstBrace = original.indexOf("{");
|
|
@@ -9211,10 +9244,11 @@ function createElement({
|
|
|
9211
9244
|
if (!VALID_TAGS[sanitisedName]) {
|
|
9212
9245
|
const specUrl = "https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name";
|
|
9213
9246
|
try {
|
|
9214
|
-
|
|
9247
|
+
element.name = name;
|
|
9248
|
+
if (isValidCustomElementName(name)) {
|
|
9215
9249
|
element.slots = [];
|
|
9216
9250
|
} else {
|
|
9217
|
-
const message = 'Invalid custom element tag name: "' +
|
|
9251
|
+
const message = 'Invalid custom element tag name: "' + name + '" (' + specUrl + ")";
|
|
9218
9252
|
if (typeof onError === "function") {
|
|
9219
9253
|
onError({
|
|
9220
9254
|
level: "WARN",
|
|
@@ -9462,18 +9496,68 @@ ScriptManager.prototype.getHelpers = function() {
|
|
|
9462
9496
|
}
|
|
9463
9497
|
return `{${helpers}}`;
|
|
9464
9498
|
};
|
|
9465
|
-
ScriptManager.prototype.registerComponent = function({
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9499
|
+
ScriptManager.prototype.registerComponent = function({
|
|
9500
|
+
id,
|
|
9501
|
+
script = {},
|
|
9502
|
+
filePath,
|
|
9503
|
+
templateAST = null,
|
|
9504
|
+
templateValues = null,
|
|
9505
|
+
defaultValues = {},
|
|
9506
|
+
styles = "",
|
|
9507
|
+
slots = {}
|
|
9508
|
+
}) {
|
|
9509
|
+
if (!this.sharedFunctions[id]) {
|
|
9510
|
+
this.sharedFunctions[id] = {
|
|
9511
|
+
id,
|
|
9512
|
+
imports: [],
|
|
9513
|
+
components: [],
|
|
9514
|
+
filePath: `/component-${id}.js`
|
|
9515
|
+
};
|
|
9516
|
+
}
|
|
9517
|
+
const target = this.sharedFunctions[id];
|
|
9518
|
+
if (hasObjectKeys(script)) {
|
|
9519
|
+
target.script = script;
|
|
9520
|
+
}
|
|
9521
|
+
if (templateAST) {
|
|
9522
|
+
target.templateAST = templateAST;
|
|
9523
|
+
}
|
|
9524
|
+
if (templateValues) {
|
|
9525
|
+
target.templateValues = templateValues;
|
|
9526
|
+
}
|
|
9527
|
+
if (styles) {
|
|
9528
|
+
target.styles = styles;
|
|
9529
|
+
}
|
|
9530
|
+
if (filePath) {
|
|
9531
|
+
target.filePath = resolve(filePath);
|
|
9532
|
+
}
|
|
9533
|
+
if (hasObjectKeys(defaultValues)) {
|
|
9534
|
+
if (target.defaultValues) {
|
|
9535
|
+
target.defaultValues = {
|
|
9536
|
+
...target.defaultValues,
|
|
9537
|
+
...defaultValues
|
|
9538
|
+
};
|
|
9539
|
+
} else {
|
|
9540
|
+
target.defaultValues = defaultValues;
|
|
9541
|
+
}
|
|
9542
|
+
}
|
|
9543
|
+
if (hasObjectKeys(slots)) {
|
|
9544
|
+
if (target.slots) {
|
|
9545
|
+
target.slots = {
|
|
9546
|
+
...target.slots,
|
|
9547
|
+
...slots
|
|
9548
|
+
};
|
|
9549
|
+
} else {
|
|
9550
|
+
target.slots = slots;
|
|
9551
|
+
}
|
|
9552
|
+
}
|
|
9553
|
+
if (script) {
|
|
9554
|
+
if (script.imports?.length) {
|
|
9555
|
+
target.imports = mergeUniqueObjects(target.imports, script.imports);
|
|
9556
|
+
}
|
|
9557
|
+
if (script.components?.length) {
|
|
9558
|
+
target.components = mergeUniqueObjects(target.components, script.components);
|
|
9559
|
+
}
|
|
9560
|
+
}
|
|
9477
9561
|
};
|
|
9478
9562
|
ScriptManager.prototype.generateInstanceWrapper = function(id, instanceContext) {
|
|
9479
9563
|
const values = instanceContext.values ? serialize(instanceContext.values) : "{}";
|
|
@@ -9607,6 +9691,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9607
9691
|
entryCodeParts.push("const coraliteComponentDefaults = {\n");
|
|
9608
9692
|
for (const key of processedComponentKeys) {
|
|
9609
9693
|
if (this.sharedFunctions[key] && this.sharedFunctions[key].defaultValues) {
|
|
9694
|
+
normalizeObjectFunctions(this.sharedFunctions[key].defaultValues);
|
|
9610
9695
|
entryCodeParts.push(` "${key}": (() => {
|
|
9611
9696
|
`);
|
|
9612
9697
|
entryCodeParts.push(` const defaults = ${serialize(this.sharedFunctions[key].defaultValues)};
|
|
@@ -9707,8 +9792,12 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9707
9792
|
refs: []
|
|
9708
9793
|
});
|
|
9709
9794
|
const styles = JSON.stringify(this.sharedFunctions[componentId].styles || "");
|
|
9795
|
+
if (this.sharedFunctions[componentId].defaultValues) {
|
|
9796
|
+
normalizeObjectFunctions(this.sharedFunctions[componentId].defaultValues);
|
|
9797
|
+
}
|
|
9710
9798
|
const defaults = serialize(this.sharedFunctions[componentId].defaultValues || {});
|
|
9711
9799
|
const dependencies = JSON.stringify(this.sharedFunctions[componentId].components || []);
|
|
9800
|
+
const slots = serialize(this.sharedFunctions[componentId].slots || {});
|
|
9712
9801
|
componentEntryCode += `
|
|
9713
9802
|
export default {
|
|
9714
9803
|
componentId: "${componentId}",
|
|
@@ -9716,6 +9805,7 @@ export default {
|
|
|
9716
9805
|
templateValues: ${templateValues},
|
|
9717
9806
|
styles: ${styles},
|
|
9718
9807
|
defaultValues: (() => { const defaults = ${defaults}; return defaults; })(),
|
|
9808
|
+
slots: (() => { const slots = ${slots}; return slots; })(),
|
|
9719
9809
|
dependencies: ${dependencies},
|
|
9720
9810
|
imports: ${hasImports ? "componentImports" : "{}"},
|
|
9721
9811
|
script: componentScript
|
|
@@ -10071,10 +10161,10 @@ var defineComponent = createPlugin({
|
|
|
10071
10161
|
* It is used to register components with their associated tokens and slots.
|
|
10072
10162
|
*
|
|
10073
10163
|
* @param {Object} options - Configuration options for the component
|
|
10074
|
-
* @param {Object.<string, (string |
|
|
10164
|
+
* @param {Object.<string, (string | CoraliteModuleTokenFunction)>} [options.tokens] -
|
|
10075
10165
|
* Computed tokens that will be available in the template. These can be
|
|
10076
10166
|
* strings or functions that return values.
|
|
10077
|
-
* @param {Object.<string,
|
|
10167
|
+
* @param {Object.<string, CoraliteModuleSlotFunction>} [options.slots] -
|
|
10078
10168
|
* Computed slots for the component. These are functions that define
|
|
10079
10169
|
* how content should be rendered within the component.
|
|
10080
10170
|
* @param {Object} [options.client] - Client side configuration.
|
|
@@ -10096,9 +10186,16 @@ var defineComponent = createPlugin({
|
|
|
10096
10186
|
element
|
|
10097
10187
|
} = context;
|
|
10098
10188
|
let results = { ...values };
|
|
10189
|
+
results.__script__ = {
|
|
10190
|
+
values: {},
|
|
10191
|
+
components: client?.components || [],
|
|
10192
|
+
defaultValues: {},
|
|
10193
|
+
slots: slots || {}
|
|
10194
|
+
};
|
|
10099
10195
|
if (client && client.setup) {
|
|
10100
10196
|
const initialValues = await client.setup(results);
|
|
10101
10197
|
results = Object.assign(results, initialValues);
|
|
10198
|
+
Object.assign(results.__script__.defaultValues, initialValues);
|
|
10102
10199
|
}
|
|
10103
10200
|
if (typeof tokens === "object" && tokens !== null) {
|
|
10104
10201
|
for (const key in tokens) {
|
|
@@ -10106,7 +10203,10 @@ var defineComponent = createPlugin({
|
|
|
10106
10203
|
const token = tokens[key];
|
|
10107
10204
|
let result = token;
|
|
10108
10205
|
if (typeof token === "function") {
|
|
10206
|
+
results.__script__.defaultValues[key] = token;
|
|
10109
10207
|
result = await token(results);
|
|
10208
|
+
} else {
|
|
10209
|
+
results.__script__.defaultValues[key] = token;
|
|
10110
10210
|
}
|
|
10111
10211
|
if (result) {
|
|
10112
10212
|
results[key] = await processTokenValue(result, {
|
|
@@ -10126,12 +10226,14 @@ var defineComponent = createPlugin({
|
|
|
10126
10226
|
const computedSlot = slots[name];
|
|
10127
10227
|
const slotContent = [];
|
|
10128
10228
|
const elementSlots = [];
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10229
|
+
if (element && element.slots) {
|
|
10230
|
+
for (let i = 0; i < element.slots.length; i++) {
|
|
10231
|
+
const slot = element.slots[i];
|
|
10232
|
+
if (slot.name === name) {
|
|
10233
|
+
slotContent.push(slot.node);
|
|
10234
|
+
} else {
|
|
10235
|
+
elementSlots.push(slot);
|
|
10236
|
+
}
|
|
10135
10237
|
}
|
|
10136
10238
|
}
|
|
10137
10239
|
const result = computedSlot(slotContent, results) || slotContent;
|
|
@@ -10170,28 +10272,30 @@ var defineComponent = createPlugin({
|
|
|
10170
10272
|
}
|
|
10171
10273
|
}
|
|
10172
10274
|
}
|
|
10173
|
-
element
|
|
10275
|
+
if (element) {
|
|
10276
|
+
element.slots = elementSlots;
|
|
10277
|
+
}
|
|
10174
10278
|
}
|
|
10175
10279
|
}
|
|
10176
10280
|
}
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10281
|
+
const hasScript = client && typeof client.script === "function";
|
|
10282
|
+
const hasSetup = client && typeof client.setup === "function";
|
|
10283
|
+
const hasComponents = client && client.components && client.components.length > 0;
|
|
10284
|
+
const hasTokens = typeof tokens === "object" && tokens !== null && Object.keys(tokens).length > 0;
|
|
10285
|
+
if (hasScript || hasSetup || hasComponents || hasTokens) {
|
|
10286
|
+
if (hasScript) {
|
|
10287
|
+
const scriptTextContent = client.script.toString().trim();
|
|
10288
|
+
const args = {};
|
|
10289
|
+
for (const key in results) {
|
|
10290
|
+
if (!Object.hasOwn(results, key)) continue;
|
|
10291
|
+
if (scriptTextContent.includes(key)) {
|
|
10292
|
+
args[key] = results[key];
|
|
10293
|
+
}
|
|
10294
|
+
}
|
|
10295
|
+
results.__script__.values = args;
|
|
10296
|
+
if (client.imports) {
|
|
10297
|
+
results.__script__.imports = client.imports;
|
|
10184
10298
|
}
|
|
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
10299
|
}
|
|
10196
10300
|
} else {
|
|
10197
10301
|
delete results.__script__;
|
|
@@ -10257,7 +10361,13 @@ var metadataPlugin = createPlugin({
|
|
|
10257
10361
|
id: element.name,
|
|
10258
10362
|
values,
|
|
10259
10363
|
element,
|
|
10260
|
-
component:
|
|
10364
|
+
component: (
|
|
10365
|
+
/** @type {any} */
|
|
10366
|
+
{
|
|
10367
|
+
...elements,
|
|
10368
|
+
path: data2.path
|
|
10369
|
+
}
|
|
10370
|
+
),
|
|
10261
10371
|
contextId: data2.path.pathname + i3 + element.name,
|
|
10262
10372
|
index: i3
|
|
10263
10373
|
});
|
|
@@ -11187,6 +11297,13 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11187
11297
|
// Merge defaults
|
|
11188
11298
|
this._values = Object.assign({}, module.default.defaultValues, this._values);
|
|
11189
11299
|
|
|
11300
|
+
if (module.default.templateValues && module.default.templateValues.refs) {
|
|
11301
|
+
for (let i = 0; i < module.default.templateValues.refs.length; i++) {
|
|
11302
|
+
const ref = module.default.templateValues.refs[i];
|
|
11303
|
+
this._values['ref_' + ref.name] = this.componentId + '__' + ref.name + '-' + this._index;
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
|
|
11190
11307
|
;(async () => {
|
|
11191
11308
|
const deps = module.default.dependencies || [];
|
|
11192
11309
|
if (deps.length > 0) {
|
|
@@ -11337,7 +11454,18 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11337
11454
|
for (let i = 0; i < slots.length; i++) {
|
|
11338
11455
|
const slot = slots[i];
|
|
11339
11456
|
const slotName = slot.getAttribute('name') || 'default';
|
|
11340
|
-
|
|
11457
|
+
let projectedNodes = this._lightDomSlots[slotName];
|
|
11458
|
+
|
|
11459
|
+
if (module.default.slots && typeof module.default.slots[slotName] === 'function') {
|
|
11460
|
+
const computedResult = module.default.slots[slotName](projectedNodes || [], this._values);
|
|
11461
|
+
if (typeof computedResult === 'string') {
|
|
11462
|
+
const tempDiv = document.createElement('div');
|
|
11463
|
+
tempDiv.innerHTML = computedResult;
|
|
11464
|
+
projectedNodes = Array.from(tempDiv.childNodes);
|
|
11465
|
+
} else if (Array.isArray(computedResult)) {
|
|
11466
|
+
projectedNodes = computedResult;
|
|
11467
|
+
}
|
|
11468
|
+
}
|
|
11341
11469
|
|
|
11342
11470
|
if (projectedNodes && projectedNodes.length > 0) {
|
|
11343
11471
|
// We have content to project, clear the fallback content
|
|
@@ -11708,6 +11836,7 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
|
|
|
11708
11836
|
};
|
|
11709
11837
|
let nestedComponents = [];
|
|
11710
11838
|
let defaultValues = {};
|
|
11839
|
+
let slots = {};
|
|
11711
11840
|
if (scriptResult.__script__) {
|
|
11712
11841
|
const extractedScript = findAndExtractScript(module.script);
|
|
11713
11842
|
if (extractedScript) {
|
|
@@ -11720,12 +11849,47 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
|
|
|
11720
11849
|
nestedComponents = Array.from(/* @__PURE__ */ new Set([...scriptComponents, ...declarativeComponents]));
|
|
11721
11850
|
scriptObj.components = nestedComponents;
|
|
11722
11851
|
defaultValues = scriptResult.__script__.defaultValues || {};
|
|
11852
|
+
slots = scriptResult.__script__.slots || {};
|
|
11723
11853
|
delete scriptResult.__script__;
|
|
11724
11854
|
} else {
|
|
11725
11855
|
const declarativeComponents = (module.customElements || []).map((el) => el.name);
|
|
11726
11856
|
nestedComponents = Array.from(/* @__PURE__ */ new Set([...declarativeComponents]));
|
|
11727
11857
|
scriptObj.components = nestedComponents;
|
|
11728
11858
|
}
|
|
11859
|
+
const componentTokens = {};
|
|
11860
|
+
for (let i = 0; i < module.values.attributes.length; i++) {
|
|
11861
|
+
const item = module.values.attributes[i];
|
|
11862
|
+
for (let j = 0; j < item.tokens.length; j++) {
|
|
11863
|
+
componentTokens[item.tokens[j].name] = true;
|
|
11864
|
+
}
|
|
11865
|
+
}
|
|
11866
|
+
for (let i = 0; i < module.values.textNodes.length; i++) {
|
|
11867
|
+
const item = module.values.textNodes[i];
|
|
11868
|
+
for (let j = 0; j < item.tokens.length; j++) {
|
|
11869
|
+
componentTokens[item.tokens[j].name] = true;
|
|
11870
|
+
}
|
|
11871
|
+
}
|
|
11872
|
+
for (const token of Object.keys(componentTokens)) {
|
|
11873
|
+
if (defaultValues[token] === void 0 && scriptResult[token] !== void 0) {
|
|
11874
|
+
defaultValues[token] = scriptResult[token];
|
|
11875
|
+
}
|
|
11876
|
+
}
|
|
11877
|
+
if (templateValues && templateValues.refs) {
|
|
11878
|
+
for (let i = 0; i < templateValues.refs.length; i++) {
|
|
11879
|
+
const ref2 = templateValues.refs[i];
|
|
11880
|
+
defaultValues[`ref_${ref2.name}`] = "";
|
|
11881
|
+
if (!scriptObj.values) {
|
|
11882
|
+
scriptObj.values = {};
|
|
11883
|
+
}
|
|
11884
|
+
scriptObj.values[`ref_${ref2.name}`] = "";
|
|
11885
|
+
}
|
|
11886
|
+
}
|
|
11887
|
+
if (!scriptResult.__script__) {
|
|
11888
|
+
scriptResult.__script__ = { defaultValues };
|
|
11889
|
+
} else {
|
|
11890
|
+
scriptResult.__script__.defaultValues = defaultValues;
|
|
11891
|
+
}
|
|
11892
|
+
scriptObj.defaultValues = defaultValues;
|
|
11729
11893
|
this._scriptManager.registerComponent({
|
|
11730
11894
|
id: module.id,
|
|
11731
11895
|
script: scriptObj,
|
|
@@ -11733,7 +11897,8 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
|
|
|
11733
11897
|
templateAST,
|
|
11734
11898
|
templateValues,
|
|
11735
11899
|
defaultValues,
|
|
11736
|
-
styles: stylesHTML
|
|
11900
|
+
styles: stylesHTML,
|
|
11901
|
+
slots
|
|
11737
11902
|
});
|
|
11738
11903
|
if (nestedComponents.length > 0) {
|
|
11739
11904
|
await this._processDependentComponents(nestedComponents, renderContext, parentComponent);
|
|
@@ -11826,7 +11991,7 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
11826
11991
|
const componentDefaultValues = scriptResult.__script__.defaultValues || {};
|
|
11827
11992
|
if (values) {
|
|
11828
11993
|
for (const token of Object.keys(componentTokens)) {
|
|
11829
|
-
if (
|
|
11994
|
+
if (componentDefaultValues[token] === void 0 && values[token] !== void 0) {
|
|
11830
11995
|
componentDefaultValues[token] = values[token];
|
|
11831
11996
|
}
|
|
11832
11997
|
}
|
|
@@ -11844,7 +12009,8 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
11844
12009
|
templateAST,
|
|
11845
12010
|
templateValues,
|
|
11846
12011
|
defaultValues: componentDefaultValues,
|
|
11847
|
-
styles: stylesHTML
|
|
12012
|
+
styles: stylesHTML,
|
|
12013
|
+
slots: scriptResult.__script__.slots || {}
|
|
11848
12014
|
});
|
|
11849
12015
|
if (mergedComponents.length > 0) {
|
|
11850
12016
|
await this._processDependentComponents(mergedComponents, renderContext, component);
|
|
@@ -11951,23 +12117,23 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
11951
12117
|
contextId: childContextId,
|
|
11952
12118
|
index,
|
|
11953
12119
|
renderContext
|
|
11954
|
-
}, false).then((
|
|
11955
|
-
|
|
12120
|
+
}, false).then((childComponentElement) => ({
|
|
12121
|
+
childComponentElement,
|
|
11956
12122
|
customElement
|
|
11957
12123
|
}))
|
|
11958
12124
|
);
|
|
11959
12125
|
}
|
|
11960
12126
|
const results = await Promise.all(createComponentTasks);
|
|
11961
12127
|
for (let i = 0; i < results.length; i++) {
|
|
11962
|
-
const {
|
|
12128
|
+
const { childComponentElement, customElement } = results[i];
|
|
11963
12129
|
const children = customElement.parent.children;
|
|
11964
12130
|
if (!childIndex) {
|
|
11965
12131
|
childIndex = customElement.parentChildIndex;
|
|
11966
12132
|
} else {
|
|
11967
12133
|
childIndex = children.indexOf(customElement, customElement.parentChildIndex);
|
|
11968
12134
|
}
|
|
11969
|
-
if (
|
|
11970
|
-
children.splice(childIndex, 1, ...
|
|
12135
|
+
if (childComponentElement && typeof childComponentElement === "object") {
|
|
12136
|
+
children.splice(childIndex, 1, ...childComponentElement.children);
|
|
11971
12137
|
}
|
|
11972
12138
|
}
|
|
11973
12139
|
const slots = module.slotElements[id];
|
|
@@ -12006,8 +12172,8 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
12006
12172
|
for (let i2 = startIndex; i2 > -1; i2--) {
|
|
12007
12173
|
const node = slotNodes[i2];
|
|
12008
12174
|
if (node.name) {
|
|
12009
|
-
const
|
|
12010
|
-
if (
|
|
12175
|
+
const slotComponentItem = this.components.getItem(node.name);
|
|
12176
|
+
if (slotComponentItem) {
|
|
12011
12177
|
const slotContextId = contextId + slotName + i2 + node.name;
|
|
12012
12178
|
const currentValues = renderContext.values[slotContextId] || {};
|
|
12013
12179
|
const attribValues = cleanKeys(node.attribs);
|
|
@@ -12024,7 +12190,7 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
12024
12190
|
id: node.name,
|
|
12025
12191
|
values: renderContext.values[slotContextId],
|
|
12026
12192
|
element: node,
|
|
12027
|
-
component
|
|
12193
|
+
component,
|
|
12028
12194
|
contextId: slotContextId,
|
|
12029
12195
|
index,
|
|
12030
12196
|
renderContext
|
|
@@ -12319,6 +12485,7 @@ export {
|
|
|
12319
12485
|
getHtmlFile,
|
|
12320
12486
|
getHtmlFileSync,
|
|
12321
12487
|
getHtmlFiles,
|
|
12488
|
+
hasObjectKeys,
|
|
12322
12489
|
hasValidCommentStructure,
|
|
12323
12490
|
hasValidElementStructure,
|
|
12324
12491
|
hasValidTextNodeStructure,
|
|
@@ -12334,8 +12501,10 @@ export {
|
|
|
12334
12501
|
isRemovableNode,
|
|
12335
12502
|
isValidChildNode,
|
|
12336
12503
|
kebabToCamel,
|
|
12504
|
+
mergeUniqueObjects,
|
|
12337
12505
|
metadataPlugin,
|
|
12338
12506
|
normalizeFunction,
|
|
12507
|
+
normalizeObjectFunctions,
|
|
12339
12508
|
parseHTML,
|
|
12340
12509
|
parseModule,
|
|
12341
12510
|
refsPlugin,
|