@cocreate/render 1.40.1 → 1.40.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/index.js +43 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.40.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.40.2...v1.40.3) (2024-03-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* handling of placeholder matching ([b80be78](https://github.com/CoCreate-app/CoCreate-render/commit/b80be78f2026c4a438115366e5dbc90faf323c2a))
|
|
7
|
+
* if key and data[key] is an array ([4478c11](https://github.com/CoCreate-app/CoCreate-render/commit/4478c116507b490a334e1010a2037ee6c12531c4))
|
|
8
|
+
* omit matches that do not match the if conditions ([b589020](https://github.com/CoCreate-app/CoCreate-render/commit/b5890205eeae38e5be1f4cdf4d48eed6da211afb))
|
|
9
|
+
|
|
10
|
+
## [1.40.2](https://github.com/CoCreate-app/CoCreate-render/compare/v1.40.1...v1.40.2) (2024-02-13)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* set eid if not defined ([097d15d](https://github.com/CoCreate-app/CoCreate-render/commit/097d15d894c30a4f2d1f3986715549203c056058))
|
|
16
|
+
|
|
1
17
|
## [1.40.1](https://github.com/CoCreate-app/CoCreate-render/compare/v1.40.0...v1.40.1) (2024-02-05)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -171,7 +171,7 @@ async function render({ source, element, selector, data, key, index, currentInde
|
|
|
171
171
|
renderedNodes.delete(clone)
|
|
172
172
|
clone.remove()
|
|
173
173
|
}
|
|
174
|
-
} else if (key || Array.isArray(data)) {
|
|
174
|
+
} else if (key && Array.isArray(data[key]) || Array.isArray(data)) {
|
|
175
175
|
if (update) {
|
|
176
176
|
for (let j = 0; j < data[key].length; j++) {
|
|
177
177
|
let clone
|
|
@@ -200,8 +200,10 @@ async function render({ source, element, selector, data, key, index, currentInde
|
|
|
200
200
|
|
|
201
201
|
await renderTemplate(element[i], data, key, index);
|
|
202
202
|
}
|
|
203
|
-
} else
|
|
204
|
-
|
|
203
|
+
} else {
|
|
204
|
+
let renderAs = element[i].getAttribute('render-as') || key;
|
|
205
|
+
await renderValues(element[i], data, key, renderAs);
|
|
206
|
+
}
|
|
205
207
|
|
|
206
208
|
}
|
|
207
209
|
|
|
@@ -380,8 +382,10 @@ function cloneTemplate(template) {
|
|
|
380
382
|
|
|
381
383
|
function insertElement(template, element, index, currentIndex) {
|
|
382
384
|
let eid = element.getAttribute('eid')
|
|
383
|
-
if (!eid)
|
|
384
|
-
|
|
385
|
+
if (!eid) {
|
|
386
|
+
eid = uuid.generate(6)
|
|
387
|
+
element.setAttribute('eid', eid)
|
|
388
|
+
}
|
|
385
389
|
|
|
386
390
|
if (index !== null && index >= 0) {
|
|
387
391
|
if (!template.clones)
|
|
@@ -581,6 +585,8 @@ async function renderValues(node, data, key, renderAs, keyPath, parent) {
|
|
|
581
585
|
async function renderValue(node, data, placeholder, renderAs, renderedNode) {
|
|
582
586
|
let output = placeholder;
|
|
583
587
|
let regex = /\{([^{}]+)\}/
|
|
588
|
+
let omitted = {}
|
|
589
|
+
|
|
584
590
|
let match;
|
|
585
591
|
do {
|
|
586
592
|
match = output.match(regex);
|
|
@@ -619,8 +625,7 @@ async function renderValue(node, data, placeholder, renderAs, renderedNode) {
|
|
|
619
625
|
value = getRenderValue(node, data, match[1], renderAs)
|
|
620
626
|
}
|
|
621
627
|
} else {
|
|
622
|
-
|
|
623
|
-
return output
|
|
628
|
+
omitted[`<|${match[1]}|>`] = match[0]
|
|
624
629
|
}
|
|
625
630
|
|
|
626
631
|
} catch (error) {
|
|
@@ -631,19 +636,25 @@ async function renderValue(node, data, placeholder, renderAs, renderedNode) {
|
|
|
631
636
|
if (typeof value === "object") {
|
|
632
637
|
value = JSON.stringify(value, null, 2);
|
|
633
638
|
}
|
|
634
|
-
output = output.
|
|
639
|
+
output = output.replaceAll(match[0], value);
|
|
635
640
|
} else if (renderAs) {
|
|
636
641
|
if (match[0].startsWith(`{{${renderAs}.`)) {
|
|
637
|
-
output = output.
|
|
642
|
+
output = output.replaceAll(match[0], "");
|
|
638
643
|
} else {
|
|
639
|
-
|
|
644
|
+
output = output.replaceAll(match[0], `<|${match[1]}|>`);
|
|
645
|
+
omitted[`<|${match[1]}|>`] = match[0]
|
|
640
646
|
}
|
|
641
647
|
} else {
|
|
648
|
+
// output = output.replace(match[0], `<|${match[1]}|>`);
|
|
642
649
|
match = null;
|
|
643
650
|
}
|
|
644
651
|
}
|
|
645
652
|
} while (match);
|
|
646
653
|
|
|
654
|
+
for (let key of Object.keys(omitted)) {
|
|
655
|
+
output = output.replaceAll(key, omitted[key]);
|
|
656
|
+
}
|
|
657
|
+
|
|
647
658
|
return output;
|
|
648
659
|
}
|
|
649
660
|
|
|
@@ -758,6 +769,28 @@ Actions.init({
|
|
|
758
769
|
}
|
|
759
770
|
});
|
|
760
771
|
|
|
772
|
+
Actions.init({
|
|
773
|
+
name: "render",
|
|
774
|
+
callback: async (action) => {
|
|
775
|
+
if (!action.form)
|
|
776
|
+
return
|
|
777
|
+
|
|
778
|
+
let elements
|
|
779
|
+
if (action.params)
|
|
780
|
+
elements = queryElements({ element: action.element, selector: action.params, type: 'selector' })
|
|
781
|
+
else
|
|
782
|
+
elements = queryElements({ element: action.element, prefix: 'render' })
|
|
783
|
+
|
|
784
|
+
let data = await action.form.getData()
|
|
785
|
+
for (let i = 0; i < elements.length; i++)
|
|
786
|
+
render({ source: elements[i], data: data[0] });
|
|
787
|
+
|
|
788
|
+
document.dispatchEvent(new CustomEvent('render', {
|
|
789
|
+
detail: {}
|
|
790
|
+
}));
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
|
|
761
794
|
Observer.init({
|
|
762
795
|
name: 'render',
|
|
763
796
|
observe: ['addedNodes'],
|