@supersoniks/concorde 4.6.0 → 4.7.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.
Files changed (182) hide show
  1. package/.gitlab-ci.yml +23 -0
  2. package/README.md +106 -55
  3. package/ai/AGENTS.md +52 -0
  4. package/ai/README.md +30 -0
  5. package/ai/cursor/rules/concorde-menu.mdc +15 -0
  6. package/ai/cursor/rules/concorde-scope.mdc +14 -0
  7. package/ai/cursor/rules/concorde-theme.mdc +13 -0
  8. package/ai/cursor/rules/concorde.mdc +49 -0
  9. package/ai/jetbrains/rules/concorde.md +39 -0
  10. package/ai/skills/concorde/SKILL.md +273 -0
  11. package/ai/skills/concorde-get-set-dp/SKILL.md +194 -0
  12. package/ai/skills/concorde-imports/SKILL.md +78 -0
  13. package/ai/skills/concorde-menu/SKILL.md +74 -0
  14. package/ai/skills/concorde-scope/SKILL.md +70 -0
  15. package/ai/skills/concorde-theme/SKILL.md +46 -0
  16. package/build-infos.json +1 -1
  17. package/concorde-core.bundle.js +152 -152
  18. package/concorde-core.es.js +1853 -1689
  19. package/dist/altcha-widget.js +2662 -0
  20. package/dist/concorde-core.bundle.js +152 -152
  21. package/dist/concorde-core.es.js +1853 -1689
  22. package/dist/docs-mock-api-sw.js +589 -0
  23. package/dist/docs-mock-api-sw.js.map +7 -0
  24. package/docs/altcha-widget.js +2662 -0
  25. package/docs/assets/index-D9pxaQYK.js +7508 -0
  26. package/docs/assets/index-t0-i22oI.css +1 -0
  27. package/docs/docs-mock-api-sw.js +589 -0
  28. package/docs/docs-mock-api-sw.js.map +7 -0
  29. package/docs/index.html +2 -2
  30. package/docs/src/core/components/functional/fetch/fetch.md +13 -11
  31. package/docs/src/core/components/functional/if/if.md +4 -11
  32. package/docs/src/core/components/functional/list/list.md +60 -194
  33. package/docs/src/core/components/functional/queue/queue.md +70 -85
  34. package/docs/src/core/components/functional/router/router.md +62 -97
  35. package/docs/src/core/components/functional/states/states.md +2 -2
  36. package/docs/src/core/components/functional/submit/submit.md +86 -55
  37. package/docs/src/core/components/ui/captcha/captcha.md +2 -2
  38. package/docs/src/core/components/ui/card/card.md +1 -1
  39. package/docs/src/core/components/ui/form/checkbox/checkbox.md +5 -32
  40. package/docs/src/core/components/ui/form/input/input.md +5 -30
  41. package/docs/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +6 -4
  42. package/docs/src/core/components/ui/form/radio/radio.md +5 -32
  43. package/docs/src/core/components/ui/form/select/select.md +5 -31
  44. package/docs/src/core/components/ui/form/switch/switch.md +5 -32
  45. package/docs/src/core/components/ui/loader/loader.md +1 -13
  46. package/docs/src/core/components/ui/table/table.md +3 -3
  47. package/docs/src/docs/_core-concept/dataFlow.md +73 -0
  48. package/docs/src/docs/_core-concept/subscriber.md +9 -10
  49. package/docs/src/docs/_decorators/ancestor-attribute.md +4 -3
  50. package/docs/src/docs/_decorators/auto-subscribe.md +19 -16
  51. package/docs/src/docs/_decorators/bind.md +20 -17
  52. package/docs/src/docs/_decorators/get.md +7 -4
  53. package/docs/src/docs/_decorators/handle.md +171 -0
  54. package/docs/src/docs/_decorators/on-assign.md +99 -73
  55. package/docs/src/docs/_decorators/publish.md +2 -1
  56. package/docs/src/docs/_decorators/subscribe.md +70 -9
  57. package/docs/src/docs/_decorators/wait-for-ancestors.md +13 -10
  58. package/docs/src/docs/_directives/sub.md +91 -0
  59. package/docs/src/docs/_getting-started/ai-agents.md +56 -0
  60. package/docs/src/docs/_getting-started/concorde-manual-install.md +133 -0
  61. package/docs/src/docs/_getting-started/concorde-outside.md +13 -123
  62. package/docs/src/docs/_getting-started/create-a-component.md +2 -0
  63. package/docs/src/docs/_getting-started/my-first-component.md +236 -0
  64. package/docs/src/docs/_getting-started/my-first-subscriber.md +29 -83
  65. package/docs/src/docs/_getting-started/pubsub.md +21 -134
  66. package/docs/src/docs/_getting-started/start.md +26 -18
  67. package/docs/src/docs/_misc/api-configuration.md +79 -0
  68. package/docs/src/docs/_misc/dataProviderKey.md +38 -5
  69. package/docs/src/docs/_misc/docs-mock-api.md +60 -0
  70. package/docs/src/docs/_misc/endpoint.md +2 -1
  71. package/docs/src/docs/_misc/html-integration.md +13 -0
  72. package/docs/src/docs/search/docs-search.json +4163 -873
  73. package/docs/src/tsconfig.json +380 -317
  74. package/gitlab/job_tests.sh +55 -0
  75. package/package.json +34 -3
  76. package/public/altcha-widget.js +2662 -0
  77. package/public/docs-mock-api-sw.js +589 -0
  78. package/public/docs-mock-api-sw.js.map +7 -0
  79. package/scripts/ai-init.mjs +167 -0
  80. package/scripts/docs-mock-api-vite-plugin.ts +116 -0
  81. package/scripts/docs-open-in-editor-plugin.ts +130 -0
  82. package/scripts/pre-publish.mjs +2 -1
  83. package/src/core/components/functional/example/example.ts +1 -1
  84. package/src/core/components/functional/fetch/fetch.md +13 -11
  85. package/src/core/components/functional/if/if.md +4 -11
  86. package/src/core/components/functional/list/list.demo.ts +4 -4
  87. package/src/core/components/functional/list/list.md +60 -194
  88. package/src/core/components/functional/list/list.ts +8 -7
  89. package/src/core/components/functional/queue/queue.demo.ts +1 -1
  90. package/src/core/components/functional/queue/queue.md +70 -85
  91. package/src/core/components/functional/queue/queue.ts +4 -4
  92. package/src/core/components/functional/router/router.md +62 -97
  93. package/src/core/components/functional/router/router.ts +1 -1
  94. package/src/core/components/functional/states/states.md +2 -2
  95. package/src/core/components/functional/submit/submit.md +86 -55
  96. package/src/core/components/functional/submit/submit.ts +10 -3
  97. package/src/core/components/ui/captcha/captcha.md +2 -2
  98. package/src/core/components/ui/card/card.md +1 -1
  99. package/src/core/components/ui/form/checkbox/checkbox.md +5 -32
  100. package/src/core/components/ui/form/input/input.md +5 -30
  101. package/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +6 -4
  102. package/src/core/components/ui/form/radio/radio.md +5 -32
  103. package/src/core/components/ui/form/select/select.md +5 -31
  104. package/src/core/components/ui/form/switch/switch.md +5 -32
  105. package/src/core/components/ui/loader/loader.md +1 -13
  106. package/src/core/components/ui/table/table.md +3 -3
  107. package/src/core/decorators/api.spec.ts +8 -1
  108. package/src/core/decorators/api.ts +126 -15
  109. package/src/core/directives/DataProvider.sub.spec.ts +96 -0
  110. package/src/core/directives/DataProvider.ts +109 -40
  111. package/src/core/utils/HTML.ts +42 -10
  112. package/src/core/utils/PublisherProxy.ts +33 -18
  113. package/src/core/utils/dataProviderKey.ts +23 -0
  114. package/src/core/utils/publisherPathKey.spec.ts +58 -0
  115. package/src/docs/_core-concept/dataFlow.md +73 -0
  116. package/src/docs/_core-concept/subscriber.md +9 -10
  117. package/src/docs/_decorators/ancestor-attribute.md +4 -3
  118. package/src/docs/_decorators/auto-subscribe.md +19 -16
  119. package/src/docs/_decorators/bind.md +19 -16
  120. package/src/docs/_decorators/get.md +7 -4
  121. package/src/docs/_decorators/handle.md +15 -13
  122. package/src/docs/_decorators/on-assign.md +53 -53
  123. package/src/docs/_decorators/publish.md +2 -1
  124. package/src/docs/_decorators/subscribe.md +70 -9
  125. package/src/docs/_decorators/wait-for-ancestors.md +13 -10
  126. package/src/docs/_directives/sub.md +91 -0
  127. package/src/docs/_getting-started/ai-agents.md +56 -0
  128. package/src/docs/_getting-started/concorde-manual-install.md +133 -0
  129. package/src/docs/_getting-started/concorde-outside.md +13 -123
  130. package/src/docs/_getting-started/create-a-component.md +2 -0
  131. package/src/docs/_getting-started/my-first-component.md +236 -0
  132. package/src/docs/_getting-started/my-first-subscriber.md +29 -83
  133. package/src/docs/_getting-started/pubsub.md +21 -134
  134. package/src/docs/_getting-started/start.md +26 -18
  135. package/src/docs/_misc/api-configuration.md +79 -0
  136. package/src/docs/_misc/dataProviderKey.md +34 -1
  137. package/src/docs/_misc/docs-mock-api.md +60 -0
  138. package/src/docs/_misc/endpoint.md +2 -1
  139. package/src/docs/_misc/html-integration.md +13 -0
  140. package/src/docs/code.ts +58 -12
  141. package/src/docs/components/docs-demo-sources.ts +397 -0
  142. package/src/docs/components/docs-lit-demo-raw.ts +28 -0
  143. package/src/docs/components/docs-lit-demo.ts +166 -0
  144. package/src/docs/components/docs-source-link.ts +72 -0
  145. package/src/docs/docs-location.ts +54 -0
  146. package/src/docs/docs.ts +12 -0
  147. package/src/docs/example/decorators-demo-bind-demos.ts +41 -46
  148. package/src/docs/example/decorators-demo-geo.ts +16 -11
  149. package/src/docs/example/decorators-demo-init.ts +2 -228
  150. package/src/docs/example/decorators-demo-subscribe-publish-get-demos.ts +54 -14
  151. package/src/docs/example/decorators-demo.ts +71 -70
  152. package/src/docs/example/docs-api-config-demos.ts +234 -0
  153. package/src/docs/example/docs-joke-demos.ts +297 -0
  154. package/src/docs/example/docs-list-demos.ts +179 -0
  155. package/src/docs/example/docs-provider-keys.ts +315 -0
  156. package/src/docs/example/docs-queue-demos.ts +114 -0
  157. package/src/docs/example/docs-router-demos.ts +89 -0
  158. package/src/docs/example/docs-submit-demos.ts +455 -0
  159. package/src/docs/example/docs-toggle-demos.ts +73 -0
  160. package/src/docs/example/docs-user-two-scopes.ts +37 -0
  161. package/src/docs/example/docs-users-list.ts +71 -0
  162. package/src/docs/example/users.ts +41 -24
  163. package/src/docs/mock-api/api-config-mock.ts +152 -0
  164. package/src/docs/mock-api/fixtures.ts +377 -0
  165. package/src/docs/mock-api/register.ts +25 -0
  166. package/src/docs/mock-api/router.ts +234 -0
  167. package/src/docs/mock-api/service-worker.ts +23 -0
  168. package/src/docs/mock-api/urls.ts +11 -0
  169. package/src/docs/navigation/navigation.ts +39 -7
  170. package/src/docs/search/docs-search.json +4021 -936
  171. package/src/docs/search/markdown-renderer.ts +7 -3
  172. package/src/docs/search/page.ts +11 -14
  173. package/src/docs/search/sonic-code-markdown.spec.ts +29 -0
  174. package/src/docs/search/sonic-code-markdown.ts +28 -0
  175. package/src/docs.ts +4 -0
  176. package/src/tsconfig.json +87 -0
  177. package/src/tsconfig.tsbuildinfo +1 -1
  178. package/vite.config.mts +8 -0
  179. package/docs/assets/index-CaysOMFz.js +0 -5046
  180. package/docs/assets/index-D8mGoXzF.css +0 -1
  181. package/docs/src/docs/_misc/templates-demo.md +0 -19
  182. package/src/docs/_misc/templates-demo.md +0 -19
@@ -59,8 +59,37 @@ class HTML {
59
59
  return null;
60
60
  }
61
61
 
62
+ /** Noms d'attribut DOM à tester (Lit reflect → minuscules, ex. serviceURL → serviceurl). */
63
+ private static scopeAttributeNames(attributeName: string): string[] {
64
+ const lower = attributeName.toLowerCase();
65
+ return lower === attributeName ? [attributeName] : [attributeName, lower];
66
+ }
67
+
68
+ private static readScopeValueOnElement(
69
+ element: HTMLElement,
70
+ attributeName: string,
71
+ ): string | null {
72
+ // Lit : la propriété est fiable avant le reflect ; un attribut vide (serviceurl="")
73
+ // ne doit pas masquer la propriété.
74
+ const prop = (element as unknown as Record<string, unknown>)[attributeName];
75
+ if (typeof prop === "string" && prop.length > 0) {
76
+ return prop;
77
+ }
78
+ for (const attrName of HTML.scopeAttributeNames(attributeName)) {
79
+ if (element.hasAttribute(attrName)) {
80
+ const attr = element.getAttribute(attrName);
81
+ if (attr != null && attr.length > 0) {
82
+ return attr;
83
+ }
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+
62
89
  /**
63
- * Va de parent en parent en partant de node pour trouver un attribut
90
+ * Va de parent en parent en partant de node pour trouver un attribut.
91
+ * Si l'attribut n'est pas encore reflété (ex. Lit `@property({ reflect: true })`
92
+ * au premier `connectedCallback`), lit la propriété homonyme sur l'élément.
64
93
  * @param attributeName nom de l'attribut
65
94
  * @returns valeur de l'attribut ou null si l'attribut n'est pas trouvé
66
95
  */
@@ -69,16 +98,19 @@ class HTML {
69
98
  attributeName: string
70
99
  ): string | null {
71
100
  if (!node) return null;
72
- while (!("hasAttribute" in node && node.hasAttribute(attributeName))) {
73
- const newNode = node.parentNode || (node as ShadowRoot).host;
74
- if (!newNode) break;
75
- node = (node.parentNode ||
76
- (node as ShadowRoot).host) as SearchableDomElement;
77
- }
78
- if (!("hasAttribute" in node)) {
79
- return null;
101
+ let current: SearchableDomElement | null = node;
102
+ while (current) {
103
+ if (current instanceof HTMLElement) {
104
+ const value = HTML.readScopeValueOnElement(current, attributeName);
105
+ if (value != null && value.length > 0) {
106
+ return value;
107
+ }
108
+ }
109
+ const parent = current.parentNode || (current as ShadowRoot).host;
110
+ if (!parent) break;
111
+ current = parent as SearchableDomElement;
80
112
  }
81
- return node.getAttribute(attributeName);
113
+ return null;
82
114
  }
83
115
 
84
116
  /**
@@ -9,6 +9,8 @@ import type {
9
9
  CoreJSType,
10
10
  PublisherContentType,
11
11
  } from "../_types/types";
12
+ import type { DataProviderKey } from "./dataProviderKey";
13
+ import { resolveStaticPublisherPath } from "./dataProviderKey";
12
14
  import HTML from "./HTML";
13
15
  import Objects from "./Objects";
14
16
  import { sonicClassPrefix } from "./Utils";
@@ -1058,13 +1060,17 @@ export const getObservables = <T = any>(
1058
1060
  return new Set<DataProvider<T>>([observable as DataProvider<T>]);
1059
1061
  };
1060
1062
 
1061
- // get value
1062
- export const get = <T = any>(id: string) => {
1063
- return getObservables<T>(id).values().next().value?.get() as T;
1064
- };
1063
+ // get value (snapshot at call time)
1064
+ export function get<T>(id: DataProviderKey<T>): T;
1065
+ export function get<T = any>(id: string): T;
1066
+ export function get<T>(id: string | DataProviderKey<T>): T {
1067
+ const path = resolveStaticPublisherPath(id);
1068
+ return getObservables<T>(path).values().next().value?.get() as T;
1069
+ }
1065
1070
 
1066
- const deepee = <T = any>(id: string) => {
1067
- const value = getObservables<T>(id).values().next().value as DataProvider<T>;
1071
+ function deepee<T>(id: string | DataProviderKey<T>, _defaultValue?: T) {
1072
+ const path = resolveStaticPublisherPath(id);
1073
+ const value = getObservables<T>(path).values().next().value as DataProvider<T>;
1068
1074
  // if (defaultValue !== undefined && value) {
1069
1075
  // const innerValue = value.get();
1070
1076
  // if (Objects.isEmpty(innerValue as Record<string, any>)) {
@@ -1073,20 +1079,29 @@ const deepee = <T = any>(id: string) => {
1073
1079
  // }
1074
1080
 
1075
1081
  return value;
1076
- };
1082
+ }
1077
1083
 
1078
- export const dataProvider: <T = any>(
1079
- id: string,
1084
+ export function dataProvider<T>(id: DataProviderKey<T>, defaultValue?: T): DataProvider<T>;
1085
+ export function dataProvider<T = any>(id: string, defaultValue?: T): DataProvider<T>;
1086
+ export function dataProvider<T>(
1087
+ id: string | DataProviderKey<T>,
1080
1088
  defaultValue?: T,
1081
- ) => DataProvider<T> = deepee;
1082
- export const dp = deepee;
1083
-
1084
- export const set: <T = any>(id: string, value: T) => void = <T>(
1085
- id: string,
1086
- value: T,
1087
- ) => {
1088
- getObservables(id).values().next().value?.set(value);
1089
- };
1089
+ ): DataProvider<T> {
1090
+ return deepee(id, defaultValue);
1091
+ }
1092
+
1093
+ export function dp<T>(id: DataProviderKey<T>, defaultValue?: T): DataProvider<T>;
1094
+ export function dp<T = any>(id: string, defaultValue?: T): DataProvider<T>;
1095
+ export function dp<T>(id: string | DataProviderKey<T>, defaultValue?: T): DataProvider<T> {
1096
+ return deepee(id, defaultValue);
1097
+ }
1098
+
1099
+ export function set<T>(id: DataProviderKey<T>, value: T): void;
1100
+ export function set<T = any>(id: string, value: T): void;
1101
+ export function set<T>(id: string | DataProviderKey<T>, value: T): void {
1102
+ const path = resolveStaticPublisherPath(id);
1103
+ getObservables(path).values().next().value?.set(value);
1104
+ }
1090
1105
 
1091
1106
  /**
1092
1107
  * next back handling data invalidation
@@ -93,6 +93,29 @@ export interface DataProviderKeyConstructor {
93
93
  new <T, U = any>(path: string): DataProviderKey<T, U>;
94
94
  }
95
95
 
96
+ /** Placeholders `${…}` / `{$…}` — resolved only by decorators (@subscribe, @publish, …). */
97
+ const DYNAMIC_PUBLISHER_PATH = /\$\{|\{\$/;
98
+
99
+ export function isDynamicPublisherPath(path: string): boolean {
100
+ return DYNAMIC_PUBLISHER_PATH.test(path);
101
+ }
102
+
103
+ export type PublisherPathInput = string | {path: string};
104
+
105
+ /**
106
+ * Resolves a static publisher path for get / set / dp.
107
+ * Rejects DataProviderKey templates with dynamic placeholders.
108
+ */
109
+ export function resolveStaticPublisherPath(input: PublisherPathInput): string {
110
+ const path = typeof input === "string" ? input : input.path;
111
+ if (isDynamicPublisherPath(path)) {
112
+ throw new Error(
113
+ "Static publisher path required for get/set/dp. Use @subscribe, @publish, or @handle for dynamic DataProviderKey paths.",
114
+ );
115
+ }
116
+ return path;
117
+ }
118
+
96
119
  /* eslint-disable @typescript-eslint/no-explicit-any */
97
120
  export const DataProviderKey: DataProviderKeyConstructor = function (
98
121
  this: any,
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ DataProviderKey,
4
+ isDynamicPublisherPath,
5
+ resolveStaticPublisherPath,
6
+ } from "./dataProviderKey";
7
+ import { dp, get, set } from "./PublisherProxy";
8
+
9
+ type Counter = { count: number };
10
+
11
+ describe("resolveStaticPublisherPath", () => {
12
+ it("accepte une string statique", () => {
13
+ expect(resolveStaticPublisherPath("myCounter")).toBe("myCounter");
14
+ });
15
+
16
+ it("accepte une DataProviderKey statique", () => {
17
+ const key = new DataProviderKey<Counter>("myCounter").count;
18
+ expect(resolveStaticPublisherPath(key)).toBe("myCounter.count");
19
+ });
20
+
21
+ it("rejette un chemin avec placeholder ${…}", () => {
22
+ expect(isDynamicPublisherPath("users.${userIndex}")).toBe(true);
23
+ expect(() =>
24
+ resolveStaticPublisherPath("users.${userIndex}"),
25
+ ).toThrow(/Static publisher path required/);
26
+ });
27
+
28
+ it("rejette une clé dynamique", () => {
29
+ const key = new DataProviderKey<Counter, { userIndex: number }>(
30
+ "users.${userIndex}",
31
+ );
32
+ expect(() => resolveStaticPublisherPath(key)).toThrow(
33
+ /Static publisher path required/,
34
+ );
35
+ });
36
+ });
37
+
38
+ describe("get / set / dp with DataProviderKey", () => {
39
+ const counterKey = new DataProviderKey<{ count: number }>(
40
+ "publisherPathKeySpecCounter",
41
+ );
42
+
43
+ it("set et get snapshot via clé racine", () => {
44
+ set(counterKey, { count: 0 });
45
+ expect(get(counterKey)).toEqual({ count: 0 });
46
+ });
47
+
48
+ it("dp sur sous-clé et écriture feuille", () => {
49
+ set(counterKey, { count: 0 });
50
+ dp(counterKey.count).set(3);
51
+ expect(get(counterKey)).toEqual({ count: 3 });
52
+ });
53
+
54
+ it("accepte encore un chemin string", () => {
55
+ set(`${counterKey.path}.legacy`, { count: 7 });
56
+ expect(get(`${counterKey.path}.legacy`)).toEqual({ count: 7 });
57
+ });
58
+ });
@@ -0,0 +1,73 @@
1
+ # Data flow
2
+
3
+ Recommended patterns for new Concorde apps (Lit + TypeScript). Under the hood, data lives in a **DataProvider** store (legacy **Publisher** API: [Legacy: Sharing data](#docs/_getting-started/pubsub.md/pubsub)).
4
+
5
+ ## Quick map
6
+
7
+ | Need | Use |
8
+ |------|-----|
9
+ | Read/write in code | `get` / `set` / `dp` + `DataProviderKey` (static paths only) |
10
+ | Reactive Lit template | `sub(key)` or `@subscribe` |
11
+ | Read component state from store | `@subscribe` + `DataProviderKey<T, U>` + `@state` |
12
+ | Inherit ancestor attributes | `@ancestorAttribute` |
13
+ | Write from component state | `@publish` |
14
+ | React to assignments | `@handle` |
15
+ | HTTP GET | `@get` + `Endpoint`, or `sonic-list` / `sonic-queue` with `fetch` |
16
+ | Forms | `formDataProvider` + `name` on fields |
17
+ | Offline doc demos | `serviceURL="/docs-mock-api"` — [Local API demos](#docs/_misc/docs-mock-api.md/docs-mock-api) |
18
+
19
+ Skill: `concorde-get-set-dp` in the package `ai/` folder.
20
+
21
+ ## DataProviderKey
22
+
23
+ <sonic-code language="typescript">
24
+ <template>
25
+ import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
26
+ import { dp, get, set } from "@supersoniks/concorde/utils";
27
+
28
+ const cartKey = new DataProviderKey&lt;{ items: string[] }&gt;("cart");
29
+
30
+ set(cartKey, { items: [] });
31
+ dp(cartKey.items).set(["a", "b"]);
32
+ get(cartKey);
33
+ </template>
34
+ </sonic-code>
35
+
36
+ Dynamic paths (`users.${userId}`) → decorators or `sub()` — not `get("users.${id}")` in imperative code.
37
+
38
+ [DataProviderKey](#docs/_misc/dataProviderKey.md/dataProviderKey)
39
+
40
+ ## Decorators
41
+
42
+ | Decorator | Role |
43
+ |-----------|------|
44
+ | `@subscribe` | Read-only property from store — [data configuration](#docs/_getting-started/my-first-component.md/my-first-component) (type + key + scope) |
45
+ | `@publish` | Push property writes to store |
46
+ | `@handle` | Method called on assignment |
47
+ | `@ancestorAttribute` | Copy ancestor HTML attribute onto property |
48
+ | `@get` | HTTP GET into `ApiGetResult&lt;T&gt;` |
49
+
50
+ Walkthrough: [My first component](#docs/_getting-started/my-first-component.md/my-first-component)
51
+
52
+ ## HTTP and lists
53
+
54
+ - [@get](#docs/_decorators/get.md/get) — single request on a component
55
+ - [List](#core/components/functional/list/list.md/list) — `fetch` + `key="data"` + `/docs-mock-api/api/users`
56
+ - [Queue](#core/components/functional/queue/queue.md/queue) — lazy `offset=$offset&per_page=$limit` + optional `dataFilterProvider` (form → query)
57
+
58
+ ## Starter kit
59
+
60
+ ```bash
61
+ npx @supersoniks/create-concorde-ts-starter my-app
62
+ ```
63
+
64
+ Interactive routes mirror these patterns (`/concepts/*`, `/demo/*`).
65
+
66
+ ## Legacy integration
67
+
68
+ | Topic | Page |
69
+ |-------|------|
70
+ | `Subscriber` / `Fetcher` mixins on app code | [Legacy: Subscriber mixin](#docs/_core-concept/subscriber.md/subscriber), [Legacy: My first subscriber](#docs/_getting-started/my-first-subscriber.md/my-first-subscriber) |
71
+ | `data-bind` HTML (plain HTML hosts) | [HTML integration](#docs/_misc/html-integration.md/html-integration) — doc demos use Lit in `src/docs/example/` |
72
+ | `@onAssign` | [@onAssign](#docs/_decorators/on-assign.md/on-assign) (prefer `@handle`) |
73
+ | `sonic-fetch` alone | [Fetch](#core/components/functional/fetch/fetch.md/fetch) |
@@ -1,12 +1,14 @@
1
- # The subscriber mixin
1
+ # Legacy: Subscriber mixin
2
2
 
3
- This is a mixin that is commonly extended by Concorde core components and destination components. Pure UI components usually don't extend it, especially those outside of form components.
3
+ > **New app components:** [My first component](#docs/_getting-started/my-first-component.md/my-first-component) and [Data flow](#docs/_core-concept/dataFlow.md/dataFlow) extend `LitElement` with decorators (`@subscribe`, `@ancestorAttribute`, …). This mixin remains in **core** components (`sonic-list`, `sonic-fetch`, …) and [legacy tutorials](#docs/_getting-started/my-first-subscriber.md/my-first-subscriber).
4
+
5
+ The Subscriber mixin was commonly extended by Concorde core components and older destination components. Pure UI components usually don't extend it, especially those outside of form components.
4
6
 
5
7
  ## DataProvider Attribute: Automatic Filling of Subscriber Properties
6
8
 
7
9
  Upon being added to the DOM (connectedCallback), subscribers search for the first occurrence of the `dataProvider` attribute in their parent's HTML structure.
8
10
 
9
- The value of this attribute is used to obtain a publisher via the PublisherManager (see [🥨 Sharing Data](#docs/_getting-started/pubsub.md/pubsub)).
11
+ The value of this attribute is the DataProvider path (see [Data flow](#docs/_core-concept/dataFlow.md/dataFlow) and [DataProviderKey](#docs/_misc/dataProviderKey.md/dataProviderKey); legacy API: [Sharing Data](#docs/_getting-started/pubsub.md/pubsub)).
10
12
 
11
13
  The subscriber then subscribes to the publisher as a data template to be filled.
12
14
 
@@ -51,14 +53,11 @@ Suppose that:
51
53
  </sonic-code>
52
54
  - We want to keep the display of an image and its `title` attribute up to date, as well as a "contact" button to email the person in the photo. The content of the subscriber could be as follows:
53
55
 
54
- <sonic-code language="html">
55
- <template>
56
- <img data-bind ::src="$img.avatar" ::title="ucFirst|$img.caption" />
57
- <a data-bind ::href="mailto:$email" ::inner-html="$email"></a>
58
- </template>
59
- </sonic-code>
56
+ In a **Lit** app, use the same data with [data configuration](#docs/_getting-started/my-first-component.md/my-first-component) (`@subscribe` + `DataProviderKey`) on a small row component — see `docs-user` in `src/docs/example/users.ts`.
57
+
58
+ For **HTML-only** embedding (no Lit), attribute binding is described in [HTML integration](#docs/_misc/html-integration.md/html-integration) and in the Legacy [Subscriber mixin](#docs/_core-concept/subscriber.md/subscriber) pages.
60
59
 
61
- This example also illustrates:
60
+ This pattern also illustrates:
62
61
 
63
62
  - Binding to subproperties using dot syntax, as done for the `src` attribute of the `img` tag.
64
63
  - Using a simple expression to include the property within a string, as in creating a `mailto` link.
@@ -25,15 +25,15 @@ The component reads `dataProvider` and `testAttribute` from its ancestor wrapper
25
25
  import { html, LitElement } from "lit";
26
26
  import { customElement } from "lit/decorators.js";
27
27
  import { ancestorAttribute } from "@supersoniks/concorde/decorators";
28
- //
28
+
29
29
  @customElement("demo-ancestor-attribute")
30
30
  export class DemoAncestorAttribute extends LitElement {
31
31
  @ancestorAttribute("dataProvider")
32
32
  dataProvider: string | null = null;
33
- //
33
+
34
34
  @ancestorAttribute("testAttribute")
35
35
  testAttribute: string | null = null;
36
- //
36
+
37
37
  render() {
38
38
  return html`
39
39
  <section>
@@ -49,6 +49,7 @@ export class DemoAncestorAttribute extends LitElement {
49
49
  <sonic-code>
50
50
  <template>
51
51
  <div dataProvider="demoDataProvider" testAttribute="test-value-123">
52
+ <docs-demo-sources for="demo-ancestor-attribute"></docs-demo-sources>
52
53
  <demo-ancestor-attribute></demo-ancestor-attribute>
53
54
  </div>
54
55
  </template>
@@ -1,5 +1,7 @@
1
1
  # @autoSubscribe
2
2
 
3
+ > **Legacy:** prefer [@subscribe](#docs/_decorators/subscribe.md/subscribe) + `DataProviderKey`. Examples below may still show `PublisherManager` for existing codebases.
4
+
3
5
  The `@autoSubscribe` decorator automatically detects which publishers are accessed within a method and subscribes to them. When any of these publishers change, the method is automatically re-executed.
4
6
 
5
7
  ## Principle
@@ -24,10 +26,10 @@ import { autoSubscribe } from "@supersoniks/concorde/decorators";
24
26
  @customElement("demo-auto-subscribe")
25
27
  export class DemoAutoSubscribe extends LitElement {
26
28
  static styles = [tailwind];
27
- //
29
+
28
30
  @state() displayText: string = "";
29
31
  @state() computedValue: number = 0;
30
- //
32
+
31
33
  @autoSubscribe()
32
34
  updateDisplay() {
33
35
  const value1 = PublisherManager.get("autoValue1").get() || 0;
@@ -35,7 +37,7 @@ export class DemoAutoSubscribe extends LitElement {
35
37
  this.computedValue = value1 + value2;
36
38
  this.displayText = `${value1} + ${value2} = ${this.computedValue}`;
37
39
  }
38
- //
40
+
39
41
  render() {
40
42
  return html`
41
43
  <p><strong>${this.displayText}</strong></p>
@@ -49,7 +51,7 @@ export class DemoAutoSubscribe extends LitElement {
49
51
  </div>
50
52
  `;
51
53
  }
52
- //
54
+
53
55
  randomizeValue(publisherId: string) {
54
56
  const value = PublisherManager.get(publisherId);
55
57
  value.set(Math.floor(Math.random() * 100));
@@ -61,6 +63,7 @@ export class DemoAutoSubscribe extends LitElement {
61
63
 
62
64
  <sonic-code >
63
65
  <template>
66
+ <docs-demo-sources for="demo-auto-subscribe"></docs-demo-sources>
64
67
  <demo-auto-subscribe></demo-auto-subscribe>
65
68
  </template>
66
69
  </sonic-code>
@@ -75,12 +78,12 @@ export class ReactiveView extends LitElement {
75
78
  render() {
76
79
  const data = PublisherManager.get("myData");
77
80
  const config = PublisherManager.get("config");
78
- //
81
+
79
82
  // This render method will be automatically re-executed
80
83
  // when myData or config change
81
84
  const value = data.get()?.value || 0;
82
85
  const multiplier = config.get()?.multiplier || 1;
83
- //
86
+
84
87
  return html`
85
88
  <div>
86
89
  <h1>Result: ${value * multiplier}</h1>
@@ -125,40 +128,40 @@ import { html, LitElement } from "lit";
125
128
  import { customElement } from "lit/decorators.js";
126
129
  import { autoSubscribe } from "@supersoniks/concorde/decorators";
127
130
  import { PublisherManager } from "@supersoniks/concorde/core/utils/PublisherProxy";
128
- //
131
+
129
132
  @customElement("shopping-cart")
130
133
  export class ShoppingCart extends LitElement {
131
134
  items: any[] = [];
132
135
  total: number = 0;
133
136
  discount: number = 0;
134
- //
137
+
135
138
  @autoSubscribe()
136
139
  calculateTotal() {
137
140
  const cart = PublisherManager.get("cart");
138
141
  const promo = PublisherManager.get("promo");
139
- //
142
+
140
143
  // Access cart items
141
144
  this.items = cart.items.get() || [];
142
- //
145
+
143
146
  // Access promo code
144
147
  const promoCode = promo.code.get() || "";
145
148
  const discountPercent = promoCode === "SAVE10" ? 0.1 : 0;
146
- //
149
+
147
150
  // Calculate totals
148
151
  const subtotal = this.items.reduce((sum, item) =>
149
152
  sum + (item.price * item.quantity), 0
150
153
  );
151
154
  this.discount = subtotal * discountPercent;
152
155
  this.total = subtotal - this.discount;
153
- //
156
+
154
157
  this.requestUpdate();
155
158
  }
156
- //
159
+
157
160
  connectedCallback() {
158
161
  super.connectedCallback();
159
162
  this.calculateTotal();
160
163
  }
161
- //
164
+
162
165
  render() {
163
166
  return html`
164
167
  <div class="cart">
@@ -175,14 +178,14 @@ export class ShoppingCart extends LitElement {
175
178
  `;
176
179
  }
177
180
  }
178
- //
181
+
179
182
  // When you update the publishers, calculateTotal is automatically called:
180
183
  const cart = PublisherManager.get("cart");
181
184
  cart.items.set([
182
185
  { name: "Product 1", price: 10, quantity: 2 },
183
186
  { name: "Product 2", price: 15, quantity: 1 }
184
187
  ]);
185
- //
188
+
186
189
  const promo = PublisherManager.get("promo");
187
190
  promo.code.set("SAVE10");
188
191
  // calculateTotal will be automatically called and the UI will update
@@ -8,7 +8,7 @@ For Lit re-renders, also add `@state()` on the same property.
8
8
 
9
9
  ## Principle
10
10
 
11
- The decorator subscribes via `PublisherManager` using dot notation. Publisher updates flow into the decorated property.
11
+ The decorator subscribes to the DataProvider store using dot notation or a `DataProviderKey`. Updates flow into the decorated property ([Data flow](#docs/_core-concept/dataFlow.md/dataFlow)).
12
12
 
13
13
  ## Import
14
14
 
@@ -25,26 +25,26 @@ import { bind } from "@supersoniks/concorde/decorators";
25
25
  @customElement("demo-bind")
26
26
  export class DemoBind extends LitElement {
27
27
  static styles = [tailwind];
28
- //
28
+
29
29
  @bind("demoData.firstName")
30
30
  @state()
31
31
  firstName = "";
32
- //
32
+
33
33
  @bind("demoData.lastName")
34
34
  @state()
35
35
  lastName: string = "";
36
- //
36
+
37
37
  @bind("demoData.count")
38
38
  @state()
39
39
  count: number = 0;
40
- //
40
+
41
41
  render() {
42
42
  return //......
43
43
  }
44
- //
44
+
45
45
  updateData() {
46
- const demoData = PublisherManager.get("demoData");
47
- const demoUsers = PublisherManager.get("demoUsers");
46
+ set(demoDataKey, { ...get(demoDataKey), count: get(demoDataKey).count + 1 });
47
+ // see demo-bind in src/docs/example/decorators-demo-bind-demos.ts
48
48
  const randomIndex = Math.floor(Math.random() * demoUsers.get().length);
49
49
  const randomUser = demoUsers.get()[randomIndex];
50
50
  demoData.set({
@@ -54,12 +54,13 @@ export class DemoBind extends LitElement {
54
54
  });
55
55
  }
56
56
  }
57
- //
57
+
58
58
  </template>
59
59
  </sonic-code>
60
60
 
61
61
  <sonic-code>
62
62
  <template>
63
+ <docs-demo-sources for="demo-bind"></docs-demo-sources>
63
64
  <demo-bind></demo-bind>
64
65
  </template>
65
66
  </sonic-code>
@@ -72,10 +73,10 @@ export class DemoBind extends LitElement {
72
73
  <template>
73
74
  import { bind } from "@supersoniks/concorde/decorators";
74
75
  import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
75
- //
76
+
76
77
  type Data = { count: number };
77
78
  const dataKey = new DataProviderKey<Data>("data");
78
- //
79
+
79
80
  @bind(dataKey.count, { reflect: true })
80
81
  @state()
81
82
  count: number = 0;
@@ -99,15 +100,15 @@ avatar: string;
99
100
  @customElement("demo-bind-reflect")
100
101
  export class DemoBindReflect extends LitElement {
101
102
  static styles = [tailwind];
102
- //
103
+
103
104
  @bind("bindReflectDemo.count", { reflect: true })
104
105
  @state()
105
106
  withReflect: number = 0;
106
- //
107
+
107
108
  @bind("bindReflectDemo.count")
108
109
  @state()
109
110
  withoutReflect: number = 0;
110
- //
111
+
111
112
  render() {
112
113
  return html`
113
114
  <div class="mb-3">
@@ -124,13 +125,14 @@ export class DemoBindReflect extends LitElement {
124
125
  `;
125
126
  }
126
127
  }
127
- //
128
+
128
129
  </template>
129
130
  </sonic-code>
130
131
 
131
132
  <sonic-code toggleCode>
132
133
  <template>
133
- <demo-bind-reflect></demo-bind-reflect>
134
+ <docs-demo-sources for="demo-bind-reflect"></docs-demo-sources>
135
+ <demo-bind-reflect></demo-bind-reflect>
134
136
  </template>
135
137
  </sonic-code>
136
138
 
@@ -148,6 +150,7 @@ Use `${prop}` or `${this.prop}` inside a **normal string literal** (not a JS tem
148
150
 
149
151
  <sonic-code>
150
152
  <template>
153
+ <docs-demo-sources for="demo-bind-dynamic"></docs-demo-sources>
151
154
  <demo-bind-dynamic></demo-bind-dynamic>
152
155
  </template>
153
156
  </sonic-code>
@@ -7,7 +7,7 @@ Pass an [`Endpoint<T>`](#docs/_misc/endpoint.md/endpoint) as the first argument.
7
7
  ## Configuration
8
8
 
9
9
  - **Default:** `HTML.getApiConfiguration(host)` (ancestor `serviceURL`, etc.).
10
- - **Second argument:** `DataProviderKey<APIConfiguration>` — config is read from the publisher at the resolved path; internal mutations trigger another GET.
10
+ - **Second argument:** `DataProviderKey<APIConfiguration>` — config is read from the publisher at the resolved path; internal mutations trigger another GET. See [API configuration](#docs/_misc/api-configuration.md/api-configuration) for mock demos.
11
11
 
12
12
  ## When the GET runs again
13
13
 
@@ -26,7 +26,7 @@ import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
26
26
 
27
27
  ## Minimal example
28
28
 
29
- Same demo service as [`sonic-queue`](../../core/components/functional/queue/queue.demo.ts) (`geo.api.gouv.fr`). Publisher setup lives in `decorators-demo-geo.ts` and `decorators-demo-subscribe-publish-get-demos.ts`.
29
+ Same demo service as [`sonic-queue`](../../core/components/functional/queue/queue.demo.ts) (`/docs-mock-api/geo/`). Publisher setup lives in `decorators-demo-geo.ts` and `decorators-demo-subscribe-publish-get-demos.ts`.
30
30
 
31
31
  <sonic-code language="typescript">
32
32
  <template>
@@ -40,6 +40,7 @@ payload: ApiGetResult<User> | null = null;
40
40
 
41
41
  <sonic-code>
42
42
  <template>
43
+ <docs-demo-sources for="demo-api-get"></docs-demo-sources>
43
44
  <demo-api-get></demo-api-get>
44
45
  </template>
45
46
  </sonic-code>
@@ -48,15 +49,17 @@ Dynamic config and endpoint path (`demo-api-get-configuration-key` in doc source
48
49
 
49
50
  <sonic-code>
50
51
  <template>
52
+ <docs-demo-sources for="demo-api-get-configuration-key"></docs-demo-sources>
51
53
  <demo-api-get-configuration-key></demo-api-get-configuration-key>
52
54
  </template>
53
55
  </sonic-code>
54
56
 
55
- Scoped `@get` with `@publish` / `@subscribe` on the payload (see [@publish](#docs/_decorators/publish.md/publish) and [@subscribe](#docs/_decorators/subscribe.md/subscribe)) — wrap under an ancestor with `serviceURL="https://geo.api.gouv.fr/"`:
57
+ Scoped `@get` with `@publish` / `@subscribe` on the payload (see [@publish](#docs/_decorators/publish.md/publish) and [@subscribe](#docs/_decorators/subscribe.md/subscribe)) — wrap under an ancestor with `serviceURL="/docs-mock-api/geo/"`:
56
58
 
57
59
  <sonic-code>
58
60
  <template>
59
- <div serviceURL="https://geo.api.gouv.fr/">
61
+ <div serviceURL="/docs-mock-api/geo/">
62
+ <docs-demo-sources for="demo-api-get-publish-subscribe"></docs-demo-sources>
60
63
  <demo-api-get-publish-subscribe></demo-api-get-publish-subscribe>
61
64
  </div>
62
65
  </template>