@supersoniks/concorde 5.0.5 → 5.1.0
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/.github/workflows/ci.yml +21 -0
- package/.github-export-ignore +30 -0
- package/.tmp-cem/custom-elements.json +13705 -0
- package/CONTRIBUTING.md +59 -0
- package/DEV.md +54 -0
- package/LICENSE +21 -0
- package/OPEN_SOURCE_CHECKPOINT.md +133 -0
- package/build-infos.json +1 -1
- package/concorde-3d.bundle.js +3960 -0
- package/concorde-3d.es.js +33433 -0
- package/concorde-core.bundle.js +196 -196
- package/concorde-core.es.js +3685 -3405
- package/concorde-hugging-face-infer.bundle.js +32 -0
- package/concorde-hugging-face-infer.es.js +2952 -0
- package/concorde-interactive.bundle.js +1157 -0
- package/concorde-interactive.es.js +10734 -0
- package/concorde-shader.bundle.js +116 -0
- package/concorde-shader.es.js +8353 -0
- package/concorde-webgpu.bundle.js +307 -0
- package/concorde-webgpu.es.js +8627 -0
- package/custom-elements-manifest.config.mjs +14 -0
- package/dist/concorde-core.bundle.js +196 -196
- package/dist/concorde-core.es.js +3685 -3405
- package/docs/assets/{index-wVZpLVYW.js → index-D8MVWqY6.js} +1351 -1222
- package/docs/assets/index-DiD0qYvE.css +1 -0
- package/docs/crawl/core/components/ui/alert/alert.html +71 -172
- package/docs/crawl/core/components/ui/alert-messages/alert-messages.html +5 -113
- package/docs/crawl/core/components/ui/badge/badge.html +79 -157
- package/docs/crawl/core/components/ui/button/button.html +0 -1
- package/docs/crawl/core/components/ui/captcha/captcha.html +8 -90
- package/docs/crawl/core/components/ui/card/card.html +68 -222
- package/docs/crawl/core/components/ui/divider/divider.html +31 -117
- package/docs/crawl/core/components/ui/form/fieldset/fieldset.html +101 -232
- package/docs/crawl/core/components/ui/form/form-actions/form-actions.html +52 -95
- package/docs/crawl/core/components/ui/form/form-layout/form-layout.html +38 -97
- package/docs/crawl/core/components/ui/form/input/input.html +3 -3
- package/docs/crawl/core/components/ui/form/textarea/textarea.html +3 -3
- package/docs/crawl/core/components/ui/group/group.html +38 -60
- package/docs/crawl/core/components/ui/icon/icon.html +47 -136
- package/docs/crawl/core/components/ui/image/image.html +56 -244
- package/docs/crawl/core/components/ui/link/link.html +9 -67
- package/docs/crawl/core/components/ui/loader/loader.html +23 -97
- package/docs/crawl/core/components/ui/menu/menu.html +90 -162
- package/docs/crawl/core/components/ui/modal/modal.html +50 -275
- package/docs/crawl/core/components/ui/pop/pop.html +66 -260
- package/docs/crawl/core/components/ui/progress/progress.html +30 -103
- package/docs/crawl/core/components/ui/table/table.html +171 -303
- package/docs/crawl/core/components/ui/toast/toast.html +59 -170
- package/docs/crawl/core/components/ui/tooltip/tooltip.html +29 -90
- package/docs/crawl/docs/_decorators/ancestor-attribute.html +2 -3
- package/docs/crawl/docs/_getting-started/concorde-outside.html +3 -3
- package/docs/crawl/docs/_getting-started/start.html +1 -1
- package/docs/crawl/docs/_getting-started/theming.html +63 -311
- package/docs/crawl/hubs/form-components.html +53 -75
- package/docs/crawl/index.html +6 -7
- package/docs/docs-mock-api-sw.js +0 -2
- package/docs/docs-mock-api-sw.js.map +2 -2
- package/docs/index.html +7 -9
- package/docs/llms-full.txt +456 -1703
- package/docs/llms.txt +32 -25
- package/docs/sitemap.xml +0 -3
- package/docs/src/core/components/functional/fetch/fetch.md +0 -0
- package/docs/src/core/components/functional/if/if.md +0 -0
- package/docs/src/core/components/functional/list/list.md +0 -0
- package/docs/src/core/components/functional/router/router.md +0 -0
- package/docs/src/core/components/functional/sdui/sdui.md +0 -0
- package/docs/src/core/components/functional/states/states.md +0 -0
- package/docs/src/core/components/functional/submit/submit.md +0 -0
- package/docs/src/core/components/ui/alert/alert.md +72 -147
- package/docs/src/core/components/ui/alert-messages/alert-messages.md +0 -85
- package/docs/src/core/components/ui/badge/badge.md +80 -141
- package/docs/src/core/components/ui/button/button.md +0 -1
- package/docs/src/core/components/ui/captcha/captcha.md +6 -65
- package/docs/src/core/components/ui/card/card.md +65 -183
- package/docs/src/core/components/ui/divider/divider.md +13 -107
- package/docs/src/core/components/ui/form/fieldset/fieldset.md +99 -175
- package/docs/src/core/components/ui/form/form-actions/form-actions.md +52 -75
- package/docs/src/core/components/ui/form/form-layout/form-layout.md +34 -109
- package/docs/src/core/components/ui/form/input/input.md +1 -1
- package/docs/src/core/components/ui/form/radio/radio.md +0 -0
- package/docs/src/core/components/ui/form/select/select.md +0 -0
- package/docs/src/core/components/ui/form/switch/switch.md +0 -0
- package/docs/src/core/components/ui/form/textarea/textarea.md +1 -1
- package/docs/src/core/components/ui/group/group.md +36 -36
- package/docs/src/core/components/ui/icon/icon.md +43 -132
- package/docs/src/core/components/ui/image/image.md +53 -179
- package/docs/src/core/components/ui/link/link.md +7 -45
- package/docs/src/core/components/ui/loader/loader.md +22 -79
- package/docs/src/core/components/ui/menu/menu.md +92 -133
- package/docs/src/core/components/ui/modal/modal.md +47 -163
- package/docs/src/core/components/ui/pop/pop.md +64 -262
- package/docs/src/core/components/ui/progress/progress.md +30 -76
- package/docs/src/core/components/ui/table/table.md +171 -147
- package/docs/src/core/components/ui/toast/toast.md +58 -108
- package/docs/src/core/components/ui/tooltip/tooltip.md +26 -68
- package/docs/src/docs/_core-concept/subscriber.md +0 -0
- package/docs/src/docs/_decorators/ancestor-attribute.md +2 -3
- package/docs/src/docs/_getting-started/concorde-outside.md +3 -3
- package/docs/src/docs/_getting-started/my-first-subscriber.md +0 -0
- package/docs/src/docs/_getting-started/pubsub.md +0 -0
- package/docs/src/docs/_getting-started/start.md +1 -1
- package/docs/src/docs/_getting-started/theming.md +61 -223
- package/docs/src/docs/search/docs-search.json +348 -3083
- package/docs/src/tsconfig.declarations.json +22 -0
- package/docs/src/tsconfig.emit.json +23 -0
- package/docs/src/tsconfig.json +3 -63
- package/gitlab/job_github_mirror.sh +39 -0
- package/package.json +36 -2
- package/scripts/generate-sdui-catalog.mjs +250 -0
- package/scripts/generate-sdui-catalog.spec.ts +91 -0
- package/scripts/github-export.mjs +150 -0
- package/scripts/post-build-docs.js +0 -0
- package/scripts/post-build.mjs +0 -0
- package/scripts/pre-build.mjs +15 -0
- package/src/core/components/functional/fetch/fetch.md +0 -0
- package/src/core/components/functional/if/if.md +0 -0
- package/src/core/components/functional/if/if.ts +0 -0
- package/src/core/components/functional/list/list.demo.ts +0 -0
- package/src/core/components/functional/list/list.md +0 -0
- package/src/core/components/functional/router/router.md +0 -0
- package/src/core/components/functional/router/router.ts +0 -0
- package/src/core/components/functional/sdui/SDUIDescriptorTransformer.ts +5 -5
- package/src/core/components/functional/sdui/__fixtures__/descriptors.ts +251 -0
- package/src/core/components/functional/sdui/__snapshots__/sdui-action.spec.ts.snap +73 -0
- package/src/core/components/functional/sdui/__snapshots__/sdui-incremental.spec.ts.snap +50 -0
- package/src/core/components/functional/sdui/__snapshots__/sdui-partial.spec.ts.snap +50 -0
- package/src/core/components/functional/sdui/__snapshots__/sdui.regression.spec.ts.snap +461 -0
- package/src/core/components/functional/sdui/component-catalog.gaps.json +511 -0
- package/src/core/components/functional/sdui/component-catalog.json +3103 -0
- package/src/core/components/functional/sdui/component-catalog.spec.ts +23 -0
- package/src/core/components/functional/sdui/sdui-action.spec.ts +99 -0
- package/src/core/components/functional/sdui/sdui-dom-snapshot.ts +61 -0
- package/src/core/components/functional/sdui/sdui-extension-points.md +94 -0
- package/src/core/components/functional/sdui/sdui-incremental.spec.ts +137 -0
- package/src/core/components/functional/sdui/sdui-partial.spec.ts +83 -0
- package/src/core/components/functional/sdui/sdui-partial.ts +19 -0
- package/src/core/components/functional/sdui/sdui-safe.spec.ts +188 -0
- package/src/core/components/functional/sdui/sdui-safe.ts +100 -0
- package/src/core/components/functional/sdui/sdui.md +122 -0
- package/src/core/components/functional/sdui/sdui.regression.spec.ts +64 -0
- package/src/core/components/functional/sdui/sdui.ts +442 -34
- package/src/core/components/functional/sdui/types.ts +49 -0
- package/src/core/components/functional/states/states.md +0 -0
- package/src/core/components/functional/submit/submit.md +0 -0
- package/src/core/components/functional/subscriber/subscriber.ts +0 -0
- package/src/core/components/functional/value/value.ts +0 -0
- package/src/core/components/ui/_css/size.ts +0 -0
- package/src/core/components/ui/captcha/altchaStyles.ts +0 -0
- package/src/core/components/ui/form/radio/radio.md +0 -0
- package/src/core/components/ui/form/select/select.md +0 -0
- package/src/core/components/ui/form/switch/switch.md +0 -0
- package/src/core/mixins/Subscriber.ts +0 -0
- package/src/core/utils/DataBindObserver.ts +0 -0
- package/src/core/utils/Objects.ts +0 -0
- package/src/core/utils/route.ts +0 -0
- package/src/css.d.ts +19 -0
- package/src/docs/_core-concept/subscriber.md +0 -0
- package/src/docs/_getting-started/my-first-subscriber.md +0 -0
- package/src/docs/_getting-started/pubsub.md +0 -0
- package/src/docs/example/users.ts +0 -0
- package/src/docs/search/page.ts +0 -0
- package/src/tsconfig.declarations.json +22 -0
- package/src/tsconfig.emit.json +23 -0
- package/src/tsconfig.json +90 -0
- package/src/tsconfig.tsbuildinfo +1 -1
- package/docs/assets/index-CD4WyL6o.css +0 -1
- package/docs/crawl/core/components/ui/theme/theme.html +0 -131
- package/docs/src/core/components/ui/theme/theme.md +0 -122
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import catalog from "./component-catalog.json";
|
|
3
|
+
|
|
4
|
+
describe("component-catalog.json (artefact publié)", () => {
|
|
5
|
+
it("contient des composants avec tag et props", () => {
|
|
6
|
+
expect(catalog.version).toBe(1);
|
|
7
|
+
expect(catalog.componentCount).toBeGreaterThan(10);
|
|
8
|
+
expect(catalog.components.length).toBe(catalog.componentCount);
|
|
9
|
+
|
|
10
|
+
const button = catalog.components.find(
|
|
11
|
+
(c: { tag: string }) => c.tag === "sonic-button"
|
|
12
|
+
);
|
|
13
|
+
expect(button).toBeTruthy();
|
|
14
|
+
expect(button!.props.some((p: { name: string }) => p.name === "type")).toBe(
|
|
15
|
+
true
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("expose un compteur de gaps d'annotations", () => {
|
|
20
|
+
expect(typeof catalog.insufficientAnnotationCount).toBe("number");
|
|
21
|
+
expect(catalog.insufficientAnnotationCount).toBeGreaterThan(0);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import TestUtils from "@supersoniks/concorde/test-utils/TestUtils";
|
|
3
|
+
import { formFields } from "./__fixtures__/descriptors";
|
|
4
|
+
import { snapshotLightDom } from "./sdui-dom-snapshot";
|
|
5
|
+
import type { SDUIActionDetail, SDUIDescriptor } from "./types";
|
|
6
|
+
import "./sdui";
|
|
7
|
+
import type { SonicSDUI } from "./sdui";
|
|
8
|
+
|
|
9
|
+
function clone<T>(value: T): T {
|
|
10
|
+
return structuredClone(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function flushSdui(elt: SonicSDUI) {
|
|
14
|
+
await elt.updateComplete;
|
|
15
|
+
await Promise.resolve();
|
|
16
|
+
await Promise.resolve();
|
|
17
|
+
await elt.updateComplete;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function render(descriptor: SDUIDescriptor): Promise<SonicSDUI> {
|
|
21
|
+
const [elt] = TestUtils.bootstrap(
|
|
22
|
+
`<sonic-sdui></sonic-sdui>`
|
|
23
|
+
) as unknown as SonicSDUI[];
|
|
24
|
+
elt.props = clone(descriptor) as never;
|
|
25
|
+
await flushSdui(elt);
|
|
26
|
+
return elt;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
document.body.innerHTML = "";
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("sonic-sdui sdui-action", () => {
|
|
34
|
+
it("émet sdui-action au clic avec name, context et sourceNodeId", async () => {
|
|
35
|
+
const elt = await render({
|
|
36
|
+
nodes: [
|
|
37
|
+
{
|
|
38
|
+
tagName: "button",
|
|
39
|
+
nodeId: "confirm-btn",
|
|
40
|
+
textContent: "Confirm",
|
|
41
|
+
action: { name: "confirm", context: { step: 1 } },
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const handler = vi.fn();
|
|
47
|
+
elt.addEventListener("sdui-action", handler as EventListener);
|
|
48
|
+
|
|
49
|
+
const button = elt.querySelector("button");
|
|
50
|
+
expect(button).toBeTruthy();
|
|
51
|
+
button!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
52
|
+
|
|
53
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
54
|
+
const event = handler.mock.calls[0][0] as CustomEvent<SDUIActionDetail>;
|
|
55
|
+
expect(event.type).toBe("sdui-action");
|
|
56
|
+
expect(event.bubbles).toBe(true);
|
|
57
|
+
expect(event.composed).toBe(true);
|
|
58
|
+
expect(event.detail).toEqual({
|
|
59
|
+
name: "confirm",
|
|
60
|
+
context: { step: 1 },
|
|
61
|
+
sourceNodeId: "confirm-btn",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("n'émet rien sans champ action", async () => {
|
|
66
|
+
const elt = await render({
|
|
67
|
+
nodes: [{ tagName: "button", textContent: "No action" }],
|
|
68
|
+
});
|
|
69
|
+
const handler = vi.fn();
|
|
70
|
+
elt.addEventListener("sdui-action", handler as EventListener);
|
|
71
|
+
elt.querySelector("button")!.dispatchEvent(
|
|
72
|
+
new MouseEvent("click", { bubbles: true })
|
|
73
|
+
);
|
|
74
|
+
expect(handler).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("context par défaut = {} si omis", async () => {
|
|
78
|
+
const elt = await render({
|
|
79
|
+
nodes: [
|
|
80
|
+
{
|
|
81
|
+
tagName: "button",
|
|
82
|
+
textContent: "Go",
|
|
83
|
+
action: { name: "go" },
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
const handler = vi.fn();
|
|
88
|
+
elt.addEventListener("sdui-action", handler as EventListener);
|
|
89
|
+
elt.querySelector("button")!.click();
|
|
90
|
+
const event = handler.mock.calls[0][0] as CustomEvent<SDUIActionDetail>;
|
|
91
|
+
expect(event.detail.context).toEqual({});
|
|
92
|
+
expect(event.detail.sourceNodeId).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("ne change pas le rendu formulaire (snapshot structurelle)", async () => {
|
|
96
|
+
const elt = await render(formFields);
|
|
97
|
+
expect(snapshotLightDom(elt)).toMatchSnapshot();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sérialisation stable du light-DOM produit par sonic-sdui,
|
|
3
|
+
* pour des snapshots de non-régression.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type DomSnapshot =
|
|
7
|
+
| string
|
|
8
|
+
| {
|
|
9
|
+
tag: string;
|
|
10
|
+
attrs?: Record<string, string>;
|
|
11
|
+
children?: DomSnapshot[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function snapshotNode(node: Node): DomSnapshot | null {
|
|
15
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
16
|
+
const text = (node.textContent || "").replace(/\s+/g, " ").trim();
|
|
17
|
+
return text || null;
|
|
18
|
+
}
|
|
19
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return null;
|
|
20
|
+
|
|
21
|
+
const el = node as HTMLElement;
|
|
22
|
+
const tag = el.tagName.toLowerCase();
|
|
23
|
+
const attrs: Record<string, string> = {};
|
|
24
|
+
const names = Array.from(el.attributes)
|
|
25
|
+
.map((a) => a.name)
|
|
26
|
+
.sort();
|
|
27
|
+
for (const name of names) {
|
|
28
|
+
// style inline volatile (display:contents posé par prefix/suffix / markup)
|
|
29
|
+
if (name === "style") {
|
|
30
|
+
const style = el.getAttribute(name) || "";
|
|
31
|
+
if (style.replace(/\s+/g, "") === "display:contents") {
|
|
32
|
+
attrs[name] = "display: contents";
|
|
33
|
+
} else {
|
|
34
|
+
attrs[name] = style;
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
attrs[name] = el.getAttribute(name) || "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const children: DomSnapshot[] = [];
|
|
42
|
+
for (const child of Array.from(el.childNodes)) {
|
|
43
|
+
const snap = snapshotNode(child);
|
|
44
|
+
if (snap != null) children.push(snap);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result: DomSnapshot = { tag };
|
|
48
|
+
if (Object.keys(attrs).length > 0) result.attrs = attrs;
|
|
49
|
+
if (children.length > 0) result.children = children;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Snapshot des enfants light-DOM d’un hôte (typiquement sonic-sdui). */
|
|
54
|
+
export function snapshotLightDom(host: HTMLElement): DomSnapshot[] {
|
|
55
|
+
const out: DomSnapshot[] = [];
|
|
56
|
+
for (const child of Array.from(host.childNodes)) {
|
|
57
|
+
const snap = snapshotNode(child);
|
|
58
|
+
if (snap != null) out.push(snap);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# SDUI — points d’extension publics
|
|
2
|
+
|
|
3
|
+
Aide-mémoire pour les dépôts externes (adaptateurs, shells).
|
|
4
|
+
**Pas une page de la doc site** — à lire dans le package npm
|
|
5
|
+
(`node_modules/@supersoniks/concorde/src/core/components/functional/sdui/sdui-extension-points.md`).
|
|
6
|
+
La doc utilisateur / crawl reste `sdui.md` (auto-suffisante).
|
|
7
|
+
|
|
8
|
+
**Aucune mention de protocoles tiers ici** : uniquement les API génériques Concorde.
|
|
9
|
+
|
|
10
|
+
## 1. Profil `safe` (opt-in)
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<sonic-sdui profile="safe" …>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Refusé | Autorisé |
|
|
17
|
+
|--------|----------|
|
|
18
|
+
| `js`, `markup`, `innerHTML`, `prefix`, `suffix` | `textContent`, structure, attributs, `action`, `childNodeIds` |
|
|
19
|
+
|
|
20
|
+
- Nœud refusé → ignoré + `console.warn` (pas de crash)
|
|
21
|
+
- Helper pur : `validateSafeDescriptor(descriptor)` depuis `sdui-safe`
|
|
22
|
+
|
|
23
|
+
## 2. Événement `sdui-action`
|
|
24
|
+
|
|
25
|
+
Sur un nœud :
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"tagName": "sonic-button",
|
|
30
|
+
"nodeId": "confirm",
|
|
31
|
+
"textContent": "OK",
|
|
32
|
+
"action": { "name": "confirm", "context": { "step": 1 } }
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Au clic, `sonic-sdui` émet :
|
|
37
|
+
|
|
38
|
+
- type : `sdui-action`
|
|
39
|
+
- `detail` : `{ name, context, sourceNodeId? }`
|
|
40
|
+
- `bubbles: true`, `composed: true`
|
|
41
|
+
|
|
42
|
+
Ne remplace pas `sonic-submit` / POST / `messagesKey`.
|
|
43
|
+
|
|
44
|
+
## 3. Catalogue de composants (build only)
|
|
45
|
+
|
|
46
|
+
- Fichier publié : `component-catalog.json`
|
|
47
|
+
- Import : `@supersoniks/concorde/sdui/component-catalog.json`
|
|
48
|
+
- Régénération : `yarn generate:sdui-catalog` (aussi `prebuild`)
|
|
49
|
+
- Gaps d’annotations : `component-catalog.gaps.json`
|
|
50
|
+
- **Aucun impact runtime**
|
|
51
|
+
|
|
52
|
+
## 4. Rendu partiel (opt-in)
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<sonic-sdui partial …>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Registre plat : `nodeById`
|
|
59
|
+
- Enfants par id : `childNodeIds`
|
|
60
|
+
- Id manquant + `partial` → placeholder (`data-sdui-placeholder`, `data-sdui-node-id`, `display: contents`)
|
|
61
|
+
- Sans `partial` → warning + skip
|
|
62
|
+
|
|
63
|
+
## 5. Ops incrémentales (opt-in, chemin à côté)
|
|
64
|
+
|
|
65
|
+
Le descripteur entier + rebuild reste le chemin par défaut. Les ops mutent un descripteur local et mettent à jour le DOM **chirurgicalement** (frères préservés : focus, valeurs d’input, état composants).
|
|
66
|
+
|
|
67
|
+
### Méthodes publiques sur `sonic-sdui`
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
upsertNode(node, parentId?, index?) // node.nodeId requis
|
|
71
|
+
removeNode(nodeId)
|
|
72
|
+
setData(path, value) // chemin publisher, ex. "form.email"
|
|
73
|
+
applyOp(op) // { op: "upsertNode"|"removeNode"|"setData", … }
|
|
74
|
+
endIncremental() // revient au mode props → rebuild
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Flux optionnel
|
|
78
|
+
|
|
79
|
+
Attribut `opsDataProvider` : chaque valeur assignée (`SDUIOp` ou `SDUIOp[]`) est passée à `applyOp`.
|
|
80
|
+
|
|
81
|
+
### Comportement
|
|
82
|
+
|
|
83
|
+
- Première op → clone local du descripteur + mode partial automatique
|
|
84
|
+
- `data-sdui-node-id` marque les nœuds rendus
|
|
85
|
+
- Remplacement d’un placeholder / nœud existant via `replaceWith` (pas de `removeChildren` global)
|
|
86
|
+
|
|
87
|
+
## Imports utiles
|
|
88
|
+
|
|
89
|
+
| Artefact | Chemin |
|
|
90
|
+
|----------|--------|
|
|
91
|
+
| Composant | `@supersoniks/concorde/sdui` |
|
|
92
|
+
| Types | `…/sdui/types` (via package exports / short path) |
|
|
93
|
+
| Safe | `@supersoniks/concorde/sdui-safe` |
|
|
94
|
+
| Catalogue | `@supersoniks/concorde/sdui/component-catalog.json` |
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import TestUtils from "@supersoniks/concorde/test-utils/TestUtils";
|
|
3
|
+
import { set } from "@supersoniks/concorde/core/utils/PublisherProxy";
|
|
4
|
+
import { layoutNested } from "./__fixtures__/descriptors";
|
|
5
|
+
import { snapshotLightDom } from "./sdui-dom-snapshot";
|
|
6
|
+
import {
|
|
7
|
+
SDUI_NODE_ID_ATTR,
|
|
8
|
+
SDUI_PLACEHOLDER_ATTR,
|
|
9
|
+
} from "./sdui-partial";
|
|
10
|
+
import type { SDUIDescriptor } from "./types";
|
|
11
|
+
import "./sdui";
|
|
12
|
+
import type { SonicSDUI } from "./sdui";
|
|
13
|
+
|
|
14
|
+
function clone<T>(value: T): T {
|
|
15
|
+
return structuredClone(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function flushSdui(elt: SonicSDUI) {
|
|
19
|
+
await elt.updateComplete;
|
|
20
|
+
await Promise.resolve();
|
|
21
|
+
await Promise.resolve();
|
|
22
|
+
await elt.updateComplete;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function render(descriptor: SDUIDescriptor): Promise<SonicSDUI> {
|
|
26
|
+
const [elt] = TestUtils.bootstrap(
|
|
27
|
+
`<sonic-sdui></sonic-sdui>`
|
|
28
|
+
) as unknown as SonicSDUI[];
|
|
29
|
+
elt.props = clone(descriptor) as never;
|
|
30
|
+
await flushSdui(elt);
|
|
31
|
+
return elt;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
document.body.innerHTML = "";
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("sonic-sdui ops incrémentales", () => {
|
|
39
|
+
it("upsertNode remplit un placeholder sans détruire le frère (valeur input)", async () => {
|
|
40
|
+
const [elt] = TestUtils.bootstrap(
|
|
41
|
+
`<sonic-sdui partial></sonic-sdui>`
|
|
42
|
+
) as unknown as SonicSDUI[];
|
|
43
|
+
elt.props = {
|
|
44
|
+
nodes: [
|
|
45
|
+
{
|
|
46
|
+
nodeId: "root",
|
|
47
|
+
tagName: "div",
|
|
48
|
+
attributes: { class: "root" },
|
|
49
|
+
childNodeIds: ["field", "later"],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
nodeById: {
|
|
53
|
+
field: {
|
|
54
|
+
nodeId: "field",
|
|
55
|
+
tagName: "input",
|
|
56
|
+
attributes: { type: "text", name: "email" },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
} as never;
|
|
60
|
+
await flushSdui(elt);
|
|
61
|
+
|
|
62
|
+
const input = elt.querySelector("input") as HTMLInputElement;
|
|
63
|
+
expect(input).toBeTruthy();
|
|
64
|
+
input.value = "keep-me";
|
|
65
|
+
expect(
|
|
66
|
+
elt.querySelector(`[${SDUI_PLACEHOLDER_ATTR}][data-node-id="later"]`)
|
|
67
|
+
).toBeTruthy();
|
|
68
|
+
|
|
69
|
+
elt.upsertNode(
|
|
70
|
+
{
|
|
71
|
+
nodeId: "later",
|
|
72
|
+
tagName: "span",
|
|
73
|
+
attributes: { class: "later" },
|
|
74
|
+
textContent: "arrived",
|
|
75
|
+
},
|
|
76
|
+
"root"
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(elt.querySelector(".later")?.textContent).toBe("arrived");
|
|
80
|
+
expect(
|
|
81
|
+
elt.querySelector(`[${SDUI_PLACEHOLDER_ATTR}][data-node-id="later"]`)
|
|
82
|
+
).toBeNull();
|
|
83
|
+
const inputAfter = elt.querySelector("input") as HTMLInputElement;
|
|
84
|
+
expect(inputAfter.value).toBe("keep-me");
|
|
85
|
+
expect(inputAfter).toBe(input);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("removeNode retire le nœud ciblé uniquement", async () => {
|
|
89
|
+
const elt = await render({
|
|
90
|
+
nodes: [
|
|
91
|
+
{
|
|
92
|
+
nodeId: "root",
|
|
93
|
+
tagName: "div",
|
|
94
|
+
childNodeIds: ["a", "b"],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
nodeById: {
|
|
98
|
+
a: { nodeId: "a", tagName: "span", textContent: "A" },
|
|
99
|
+
b: { nodeId: "b", tagName: "span", textContent: "B" },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
elt.removeNode("a");
|
|
104
|
+
expect(elt.querySelector(`[${SDUI_NODE_ID_ATTR}="a"]`)).toBeNull();
|
|
105
|
+
expect(elt.querySelector(`[${SDUI_NODE_ID_ATTR}="b"]`)?.textContent).toBe(
|
|
106
|
+
"B"
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("setData met à jour un dataProvider par chemin", async () => {
|
|
111
|
+
set("sdui-inc-form", { email: "" });
|
|
112
|
+
const elt = await render({ nodes: [{ tagName: "div" }] });
|
|
113
|
+
elt.setAttribute("dataProvider", "sdui-inc-form");
|
|
114
|
+
// dataProvider property may need connected publisher — set via path absolute
|
|
115
|
+
elt.setData("sdui-inc-form.email", "hi@test");
|
|
116
|
+
const { get } = await import("@supersoniks/concorde/core/utils/PublisherProxy");
|
|
117
|
+
expect(get("sdui-inc-form").email).toBe("hi@test");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("applyOp délègue correctement", async () => {
|
|
121
|
+
const elt = await render({ nodes: [] });
|
|
122
|
+
elt.applyOp({
|
|
123
|
+
op: "upsertNode",
|
|
124
|
+
node: { nodeId: "x", tagName: "p", textContent: "X" },
|
|
125
|
+
});
|
|
126
|
+
expect(elt.querySelector(`[${SDUI_NODE_ID_ATTR}="x"]`)?.textContent).toBe(
|
|
127
|
+
"X"
|
|
128
|
+
);
|
|
129
|
+
elt.applyOp({ op: "removeNode", nodeId: "x" });
|
|
130
|
+
expect(elt.querySelector(`[${SDUI_NODE_ID_ATTR}="x"]`)).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("ne régresse pas le chemin descripteur entier", async () => {
|
|
134
|
+
const elt = await render(layoutNested);
|
|
135
|
+
expect(snapshotLightDom(elt)).toMatchSnapshot();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import TestUtils from "@supersoniks/concorde/test-utils/TestUtils";
|
|
3
|
+
import { layoutNested } from "./__fixtures__/descriptors";
|
|
4
|
+
import { snapshotLightDom } from "./sdui-dom-snapshot";
|
|
5
|
+
import { SDUI_PLACEHOLDER_ATTR } from "./sdui-partial";
|
|
6
|
+
import type { SDUIDescriptor } from "./types";
|
|
7
|
+
import "./sdui";
|
|
8
|
+
import type { SonicSDUI } from "./sdui";
|
|
9
|
+
|
|
10
|
+
function clone<T>(value: T): T {
|
|
11
|
+
return structuredClone(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function flushSdui(elt: SonicSDUI) {
|
|
15
|
+
await elt.updateComplete;
|
|
16
|
+
await Promise.resolve();
|
|
17
|
+
await Promise.resolve();
|
|
18
|
+
await elt.updateComplete;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function render(
|
|
22
|
+
descriptor: SDUIDescriptor,
|
|
23
|
+
attrs: Record<string, string> = {}
|
|
24
|
+
): Promise<SonicSDUI> {
|
|
25
|
+
const attrStr = Object.entries(attrs)
|
|
26
|
+
.map(([k, v]) => `${k}="${v}"`)
|
|
27
|
+
.join(" ");
|
|
28
|
+
const [elt] = TestUtils.bootstrap(
|
|
29
|
+
`<sonic-sdui ${attrStr}></sonic-sdui>`
|
|
30
|
+
) as unknown as SonicSDUI[];
|
|
31
|
+
elt.props = clone(descriptor) as never;
|
|
32
|
+
await flushSdui(elt);
|
|
33
|
+
return elt;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
document.body.innerHTML = "";
|
|
38
|
+
vi.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const partialDescriptor: SDUIDescriptor = {
|
|
42
|
+
nodes: [
|
|
43
|
+
{
|
|
44
|
+
tagName: "div",
|
|
45
|
+
attributes: { class: "root" },
|
|
46
|
+
childNodeIds: ["present", "missing"],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
nodeById: {
|
|
50
|
+
present: {
|
|
51
|
+
nodeId: "present",
|
|
52
|
+
tagName: "span",
|
|
53
|
+
attributes: { class: "ok" },
|
|
54
|
+
textContent: "here",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
describe("sonic-sdui rendu partiel", () => {
|
|
60
|
+
it("sans partial : enfant manquant ignoré (warning), pas de placeholder", async () => {
|
|
61
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
62
|
+
const elt = await render(partialDescriptor);
|
|
63
|
+
expect(elt.querySelector(`[${SDUI_PLACEHOLDER_ATTR}]`)).toBeNull();
|
|
64
|
+
expect(elt.querySelector(".ok")?.textContent).toBe("here");
|
|
65
|
+
expect(
|
|
66
|
+
warn.mock.calls.some((c) => String(c[0]).includes('childNodeId "missing"'))
|
|
67
|
+
).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("avec partial : placeholder léger pour l'enfant manquant", async () => {
|
|
71
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
72
|
+
const elt = await render(partialDescriptor, { partial: "" });
|
|
73
|
+
const ph = elt.querySelector(`[${SDUI_PLACEHOLDER_ATTR}]`);
|
|
74
|
+
expect(ph).toBeTruthy();
|
|
75
|
+
expect(ph?.getAttribute("data-node-id")).toBe("missing");
|
|
76
|
+
expect(elt.querySelector(".ok")?.textContent).toBe("here");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ne régresse pas sur un descripteur classique (snapshot)", async () => {
|
|
80
|
+
const elt = await render(layoutNested);
|
|
81
|
+
expect(snapshotLightDom(elt)).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Marqueur DOM des placeholders de rendu partiel. */
|
|
2
|
+
export const SDUI_PLACEHOLDER_ATTR = "data-sdui-placeholder";
|
|
3
|
+
|
|
4
|
+
/** Attribut DOM portant le `nodeId` logique (pas l'id HTML). */
|
|
5
|
+
export const SDUI_NODE_ID_ATTR = "data-sdui-node-id";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Placeholder léger pour un enfant référencé pas encore disponible.
|
|
9
|
+
* `display: contents` pour ne pas perturber le layout.
|
|
10
|
+
*/
|
|
11
|
+
export function createSduiPlaceholder(nodeId: string): HTMLElement {
|
|
12
|
+
const el = document.createElement("div");
|
|
13
|
+
el.setAttribute(SDUI_PLACEHOLDER_ATTR, "");
|
|
14
|
+
el.setAttribute("data-node-id", nodeId);
|
|
15
|
+
el.setAttribute(SDUI_NODE_ID_ATTR, nodeId);
|
|
16
|
+
el.setAttribute("aria-hidden", "true");
|
|
17
|
+
el.style.display = "contents";
|
|
18
|
+
return el;
|
|
19
|
+
}
|