@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
@@ -0,0 +1,236 @@
1
+ # My first component
2
+
3
+ Build a **Lit** user card with Tailwind and Concorde UI, then connect it to the **DataProvider** store: declare the **data configuration** (type, key, scope), and let **`@subscribe`** keep the card in sync.
4
+
5
+ > Legacy approach with the **Subscriber mixin**: [Legacy: My first subscriber](#docs/_getting-started/my-first-subscriber.md/my-first-subscriber).
6
+
7
+ ## 1. Lit component + Tailwind
8
+
9
+ Export Tailwind once (e.g. `src/docs/tailwind.ts` in this repo):
10
+
11
+ <sonic-code language="typescript">
12
+ <template>
13
+ import { css, unsafeCSS } from "lit";
14
+ import tailwindImport from "./css/tailwind.css?inline";
15
+
16
+ export const tailwind = css`${unsafeCSS(tailwindImport)}`;
17
+ </template>
18
+ </sonic-code>
19
+
20
+ User card — plain Lit properties and UI components (no store yet):
21
+
22
+ <sonic-code language="typescript">
23
+ <template>
24
+ import { html, LitElement } from "lit";
25
+ import { customElement, property } from "lit/decorators.js";
26
+ import { tailwind } from "../tailwind";
27
+
28
+ @customElement("docs-user")
29
+ export class DocsUser extends LitElement {
30
+ static styles = [tailwind];
31
+
32
+ @property({ type: String }) first_name = "";
33
+ @property({ type: String }) last_name = "";
34
+ @property({ type: String }) email = "";
35
+ @property({ type: String }) avatar = "";
36
+
37
+ render() {
38
+ return html`&lt;div class="flex items-center gap-3 rounded-md p-2"&gt;
39
+ &lt;sonic-image src=${this.avatar} rounded="md" ratio="1/1" class="w-16"&gt;&lt;/sonic-image&gt;
40
+ &lt;div&gt;
41
+ &lt;div&gt;${this.first_name} &lt;span class="font-bold"&gt;${this.last_name}&lt;/span&gt;&lt;/div&gt;
42
+ &lt;div class="text-sm text-neutral-400"&gt;${this.email}&lt;/div&gt;
43
+ &lt;/div&gt;
44
+ &lt;/div&gt;`;
45
+ }
46
+ }
47
+ </template>
48
+ </sonic-code>
49
+
50
+ ## 2. Data configuration
51
+
52
+ The card does not hard-code user fields anymore. You declare **what** is stored, **where** it lives, and **which ancestor scope** applies — then `@subscribe` mirrors that object on the component.
53
+
54
+ ### Type — shape of the data
55
+
56
+ `DocsUserData` documents the fields you expect at this scope (first name, email, avatar, …). TypeScript checks that `user` matches that shape.
57
+
58
+ <sonic-code language="typescript">
59
+ <template>
60
+ export type DocsUserData = {
61
+ first_name: string;
62
+ last_name: string;
63
+ email: string;
64
+ avatar: string;
65
+ };
66
+ </template>
67
+ </sonic-code>
68
+
69
+ ### Key — path in the DataProvider
70
+
71
+ `docsUserRowKey` points at the store segment to read. The path `"${dataProvider}"` is resolved at runtime from a property on the component (see scope below).
72
+
73
+ <sonic-code language="typescript">
74
+ <template>
75
+ import { DataProviderKey } from "@supersoniks/concorde/core/utils/dataProviderKey";
76
+
77
+ export const docsUserRowKey = new DataProviderKey&lt;
78
+ DocsUserData,
79
+ { dataProvider: string | null }
80
+ &gt;("${dataProvider}");
81
+ </template>
82
+ </sonic-code>
83
+
84
+ The second generic (`{ dataProvider: string | null }`) lists what the host must expose so `"${dataProvider}"` can be resolved. See [DataProviderKey](#docs/_misc/dataProviderKey.md/dataProviderKey).
85
+
86
+ ### Scope — which store segment applies
87
+
88
+ A parent sets `dataProvider=${docsUserScopeAKey.path}` (or a list row sets `…/list-item/0`). [`@ancestorAttribute`](#docs/_decorators/ancestor-attribute.md/ancestor-attribute) copies that attribute onto `this.dataProvider`, so the key resolves to the correct branch.
89
+
90
+ <sonic-code language="typescript">
91
+ <template>
92
+ @ancestorAttribute("dataProvider")
93
+ dataProvider: string | null = null;
94
+ </template>
95
+ </sonic-code>
96
+
97
+ ### Subscribe — keep the card in sync
98
+
99
+ [`@subscribe`](#docs/_decorators/subscribe.md/subscribe) watches `docsUserRowKey` and updates `user` when the store changes. Use `@state()` so Lit re-renders. The template reads `this.user` like any other property.
100
+
101
+ <sonic-code language="typescript">
102
+ <template>
103
+ import { html, LitElement, nothing } from "lit";
104
+ import { customElement, state } from "lit/decorators.js";
105
+ import {
106
+ ancestorAttribute,
107
+ subscribe,
108
+ } from "@supersoniks/concorde/core/decorators/Subscriber";
109
+ import { docsUserRowKey, type DocsUserData } from "./users";
110
+ import { tailwind } from "../tailwind";
111
+
112
+ @customElement("docs-user")
113
+ export class DocsUser extends LitElement {
114
+ static styles = [tailwind];
115
+
116
+ @ancestorAttribute("dataProvider")
117
+ dataProvider: string | null = null;
118
+
119
+ @subscribe(docsUserRowKey)
120
+ @state()
121
+ user: DocsUserData | null = null;
122
+
123
+ render() {
124
+ const u = this.user;
125
+ if (!u) return nothing;
126
+ return html`&lt;div class="flex items-center gap-3 rounded-md p-2"&gt;
127
+ &lt;sonic-image src=${u.avatar} rounded="md" ratio="1/1" class="w-16"&gt;&lt;/sonic-image&gt;
128
+ &lt;div&gt;
129
+ &lt;div&gt;${u.first_name} &lt;span class="font-bold"&gt;${u.last_name}&lt;/span&gt;&lt;/div&gt;
130
+ &lt;div class="text-sm text-neutral-400"&gt;${u.email}&lt;/div&gt;
131
+ &lt;/div&gt;
132
+ &lt;/div&gt;`;
133
+ }
134
+ }
135
+ </template>
136
+ </sonic-code>
137
+
138
+ Live code: `src/docs/example/users.ts`. In this repo, imports use **`core/…` paths** (short `@supersoniks/concorde/…` exports apply in **consumer apps** only).
139
+
140
+ ### Two scopes, one component
141
+
142
+ The same `docs-user` is mounted twice. Each copy inherits a **different** nearest `dataProvider` — that is the row/list **scope**:
143
+
144
+ <sonic-code>
145
+ <template>
146
+ <docs-demo-sources for="docs-user-two-scopes"></docs-demo-sources>
147
+ <docs-user-two-scopes></docs-user-two-scopes>
148
+ </template>
149
+ </sonic-code>
150
+
151
+ Markup (two isolated stores; keys from `docs-provider-keys.ts`):
152
+
153
+ <sonic-code language="markup">
154
+ <template>
155
+ &lt;div class="grid md:grid-cols-2 gap-6"&gt;
156
+ &lt;div dataProvider="${docsUserScopeAKey.path}"&gt;
157
+ &lt;docs-user&gt;&lt;/docs-user&gt;
158
+ &lt;/div&gt;
159
+ &lt;div dataProvider="${docsUserScopeBKey.path}"&gt;
160
+ &lt;docs-user&gt;&lt;/docs-user&gt;
161
+ &lt;/div&gt;
162
+ &lt;/div&gt;
163
+ </template>
164
+ </sonic-code>
165
+
166
+ Seeded in `docs-provider-keys.ts` (`set(docsUserScopeAKey, …)`): **Paul** / **Marie**. Without `@ancestorAttribute`, both cards would not know which store to read.
167
+
168
+ ## 3. Fetch users — `sonic-list` with `.items`
169
+
170
+ Use a Lit parent and the **`items`** renderer (not HTML `<template>` children). The callback receives each row object from fetch — render fields directly (`${item.first_name}`, …), like porting a template that used `data-bind` / `<sonic-value>`.
171
+
172
+ <sonic-code>
173
+ <template>
174
+ <docs-lit-demo for="docs-users-list"></docs-lit-demo>
175
+ </template>
176
+ </sonic-code>
177
+
178
+ Wrapper (`docs-users-list.ts`):
179
+
180
+ <sonic-code language="typescript">
181
+ <template>
182
+ import { html, LitElement } from "lit";
183
+ import { customElement } from "lit/decorators.js";
184
+ import "../../core/components/functional/list/list";
185
+ import "./users";
186
+
187
+ @customElement("docs-users-list")
188
+ export class DocsUsersList extends LitElement {
189
+ private items = ({ first_name, last_name, email, avatar }) => html`
190
+ &lt;div class="flex gap-3"&gt;
191
+ &lt;sonic-image src=${avatar} ...&gt;&lt;/sonic-image&gt;
192
+ &lt;div&gt;${first_name} &lt;b&gt;${last_name}&lt;/b&gt;&lt;/div&gt;
193
+ &lt;div class="text-sm text-neutral-400"&gt;${email}&lt;/div&gt;
194
+ &lt;/div&gt;
195
+ `;
196
+
197
+ render() {
198
+ return html`
199
+ &lt;sonic-list fetch dataProvider=${usersListEndpoint.path} key="data" .items=${this.items}&gt;&lt;/sonic-list&gt;
200
+ `;
201
+ }
202
+ }
203
+ </template>
204
+ </sonic-code>
205
+
206
+ See [Local API demos](#docs/_misc/docs-mock-api.md/docs-mock-api) for `serviceURL="/docs-mock-api"`.
207
+
208
+ ## 4. Form preview with `formDataProvider`
209
+
210
+ Edit fields in a form; the card follows the same `docsUserRowKey` when the preview host sets `dataProvider="userPreview"`.
211
+
212
+ <sonic-code>
213
+ <template>
214
+ <div class="grid grid-cols-1 gap-4 max-w-xl">
215
+ <form formDataProvider="${docsUserPreviewKey.path}" class="grid grid-cols-2 gap-3">
216
+ <sonic-input label="First name" name="first_name" value="Paul" size="sm"></sonic-input>
217
+ <sonic-input label="Last name" name="last_name" value="Metrand" size="sm"></sonic-input>
218
+ <sonic-input class="col-span-2" label="Email" name="email" value="paul@example.com" size="sm"></sonic-input>
219
+ <sonic-input class="col-span-2" label="Avatar URL" name="avatar" value="https://i.pravatar.cc/150?u=paul" size="sm"></sonic-input>
220
+ </form>
221
+ <sonic-divider align="left">Preview</sonic-divider>
222
+ <div dataProvider="${docsUserPreviewKey.path}">
223
+ <docs-user></docs-user>
224
+ </div>
225
+ </div>
226
+ </template>
227
+ </sonic-code>
228
+
229
+ Use `formDataProvider` + `name` on inputs — no manual `@input` handlers ([Data flow](#docs/_core-concept/dataFlow.md/dataFlow)).
230
+
231
+ ## Next steps
232
+
233
+ - [Data flow](#docs/_core-concept/dataFlow.md/dataFlow) — full map
234
+ - [DataProviderKey](#docs/_misc/dataProviderKey.md/dataProviderKey) — typed paths and host constraints
235
+ - [@subscribe](#docs/_decorators/subscribe.md/subscribe) / [sub()](#docs/_directives/sub.md/sub) — read-only in templates
236
+ - [List](#core/components/functional/list/list.md/list) — `.items`, `.noItems`, `.skeleton`
@@ -1,7 +1,8 @@
1
- # My first subscriber component
1
+ # Legacy: My first subscriber component
2
2
 
3
- Learn how to build a subscriber component, styled with tailwind,
4
- which could be used as a regular component or could be filled from a dataprovider.
3
+ > **New projects:** use [My first component](#docs/_getting-started/my-first-component.md/my-first-component) (`@ancestorAttribute`, `@subscribe` + `DataProviderKey`, `.items` on lists) and [Data flow](#docs/_core-concept/dataFlow.md/dataFlow). This page documents the **Subscriber mixin** used by older apps and core components.
4
+
5
+ Learn how to build a component with the **Subscriber** mixin, styled with Tailwind, filled from a DataProvider via automatic property mapping.
5
6
 
6
7
  ## Create a classic lit component
7
8
 
@@ -9,30 +10,24 @@ which could be used as a regular component or could be filled from a dataprovide
9
10
  <template>
10
11
  import { html, LitElement, nothing } from "lit";
11
12
  import { customElement, property } from "lit/decorators.js";
12
- // name component
13
13
  @customElement("docs-user")
14
14
  export class user extends LitElement {
15
- // set a few props
16
15
  @property({ type: String }) first_name = "";
17
16
  @property({ type: String }) last_name = "";
18
17
  @property({ type: String }) avatar = "";
19
18
  @property({ type: String }) email = "";
20
- // output
21
19
  render() {
22
20
  return html`
23
- <img src="${this.avatar}" /> <br>
24
- ${this.first_name} ${this.last_name} <br>
21
+ &lt;img src="${this.avatar}" /&gt; &lt;br&gt;
22
+ ${this.first_name} ${this.last_name} &lt;br&gt;
25
23
  ${this.email}`;
26
24
  }
27
25
  }
28
26
  </template>
29
27
  </sonic-code>
30
28
 
31
-
32
29
  ### Style with tailwind and ui components
33
30
 
34
- First export tailwind, in a tailwind.ts file, stylesheet to add it in our component when needed.
35
-
36
31
  <sonic-code language="javascript">
37
32
  <template>
38
33
  import { css, unsafeCSS } from "lit";
@@ -43,132 +38,83 @@ First export tailwind, in a tailwind.ts file, stylesheet to add it in our compon
43
38
 
44
39
  <sonic-code language="javascript">
45
40
  <template>
46
- import { html, LitElement, nothing } from "lit";
41
+ import { html, LitElement } from "lit";
47
42
  import { customElement, property } from "lit/decorators.js";
48
- // add tailwind and needed components
49
43
  import { tailwind } from "../tailwind";
50
44
  import '@supersoniks/concode/ui/image'
51
45
  import '@supersoniks/concode/ui/button'
52
46
  import '@supersoniks/concode/ui/icon'
53
- //
54
47
  @customElement("docs-user")
55
48
  export class user extends LitElement {
56
- // add tailwind stylesheed
57
49
  static styles = [tailwind];
58
50
  @property({ type: String }) first_name = "";
59
51
  @property({ type: String }) last_name = "";
60
52
  @property({ type: String }) avatar = "";
61
53
  @property({ type: String }) email = "";
62
- // use utility class in your markup
63
54
  render() {
64
- return html`<div
65
- class="flex items-center gap-3 rounded-md hover:bg-neutral-50 -mx-2 p-2"
66
- >
67
- <sonic-image
68
- src=${this.avatar}
69
- rounded="md"
70
- ratio="1/1"
71
- class="w-16 block"
72
- ></sonic-image>
73
- <div>
74
- <div>
75
- ${this.first_name} <span class="font-bold">${this.last_name}</span>
76
- </div>
77
- <div class="text-sm text-neutral-400">${this.email}</div>
78
- </div>
79
- <div class="ml-auto relative">
80
- <sonic-button
81
- href="mailto:${this.email}"
82
- size="sm"
83
- variant="outline"
84
- shape="circle"
85
- class="relative"
86
- icon
87
- >
88
- <sonic-icon library="iconoir" name="chat-bubble"></sonic-icon>
89
- </sonic-button>
90
- </div>
91
- </div>`;
55
+ return html`&lt;div class="flex items-center gap-3 p-2"&gt;
56
+ &lt;sonic-image src=${this.avatar} rounded="md" ratio="1/1" class="w-16"&gt;&lt;/sonic-image&gt;
57
+ &lt;div&gt;${this.first_name} &lt;span class="font-bold"&gt;${this.last_name}&lt;/span&gt;&lt;/div&gt;
58
+ &lt;div class="text-sm text-neutral-400"&gt;${this.email}&lt;/div&gt;
59
+ &lt;/div&gt;`;
92
60
  }
93
61
  }
94
62
  </template>
95
63
  </sonic-code>
96
64
 
97
- ### Basic usage
98
-
99
- Reactive properties can be filled by its attributes as a simple lit component.
100
-
101
- <sonic-code>
102
- <template>
103
- <docs-user
104
- first_name="Paul"
105
- last_name="Metrand"
106
- avatar="/img/paul_metrand_xs.jpg"
107
- email="paulmetrand@concorde.fr"
108
- ></docs-user>
109
- </template>
110
- </sonic-code>
111
-
112
65
  ## Add Subscriber mixin
113
66
 
114
- Import Subscriber mixin, and add it around LitElement.
115
67
  <sonic-code language="javascript">
116
68
  <template>
117
- import { html, LitElement, nothing } from "lit";
118
- import { customElement, property } from "lit/decorators.js";
119
- import { tailwind } from "../tailwind";
120
69
  import Subscriber from "@supersoniks/concorde/core/mixins/Subscriber";
121
70
  @customElement("docs-user")
122
71
  export class user extends Subscriber(LitElement) {
123
- //...
72
+ // properties auto-filled from DataProvider when names match
124
73
  }
125
74
  </template>
126
75
  </sonic-code>
127
76
 
128
- ## Autofill properties from a dataProvider
77
+ See [Legacy: Subscriber mixin](#docs/_core-concept/subscriber.md/subscriber).
78
+
79
+ ## Autofill from a dataProvider
129
80
 
130
- Without a dataProvider attribute, a subscriber set its own dataprovider from first ancestor found, and then reactive properties automatically filled and update from it.
131
- A fetcher is a simple component which set its fetch result to props of its dataprovider.
132
81
  <sonic-code >
133
82
  <template>
83
+ <docs-demo-sources for="list-users-fetch"></docs-demo-sources>
84
+ <div serviceURL="/docs-mock-api">
134
85
  <sonic-fetch
135
- serviceURL="https://reqres.in"
86
+ serviceURL="/docs-mock-api"
136
87
  dataProvider="api/users/3"
137
88
  key="data">
138
89
  <docs-user></docs-user>
139
90
  </sonic-fetch>
91
+ </div>
140
92
  </template>
141
93
  </sonic-code>
142
94
 
143
- A subscriber can subscribe data from anywhere in the DOM, with its dataprovider set as a provider id.
144
95
  <sonic-code >
145
96
  <template>
146
97
  <sonic-fetch
147
- serviceURL="https://reqres.in"
98
+ serviceURL="/docs-mock-api"
148
99
  dataProvider="api/users/2"
149
100
  key="data"></sonic-fetch>
150
101
  <docs-user dataProvider="api/users/2" ></docs-user>
151
- <docs-user dataProvider="api/users/2" ></docs-user>
152
- <docs-user dataProvider="api/users/2" ></docs-user>
153
102
  </template>
154
103
  </sonic-code>
155
104
 
156
-
157
105
  <sonic-code >
158
106
  <template>
159
-
160
107
  <div class="grid grid-cols-1 gap-4">
161
108
  <form formDataProvider="userPreview" class="grid grid-cols-4 gap-3" >
162
- <sonic-input label="First name" type="text" name="first_name" placeholder="John" value="Paul"></sonic-input>
163
- <sonic-input label="Last name" type="text" name="last_name" placeholder="Doe" value="Metrand"></sonic-input>
164
- <sonic-input class="col-span-2" label="email" type="text" name="email" placeholder="johndoe@concorde.fr" value="paulmetrand@concorde.fr"></sonic-input>
165
- <sonic-input type="file" name="avatar" value="/img/paul_metrand_xs.jpg"></sonic-input>
109
+ <sonic-input label="First name" type="text" name="first_name" value="Paul" size="sm"></sonic-input>
110
+ <sonic-input label="Last name" type="text" name="last_name" value="Metrand" size="sm"></sonic-input>
111
+ <sonic-input class="col-span-2" label="email" type="text" name="email" value="paul@example.com" size="sm"></sonic-input>
112
+ <sonic-input label="Image url" type="text" name="avatar" value="https://i.pravatar.cc/150?u=paul" size="sm"></sonic-input>
166
113
  </form>
167
114
  <sonic-divider align="left">Preview before submit</sonic-divider>
168
- <docs-user dataProvider="userPreview" ></docs-user>
169
- <sonic-button onClick="alert(JSON.stringify(SonicPublisherManager.get('userPreview').get()))">
170
- Update data
171
- </sonic-button>
115
+ <div dataProvider="userPreview">
116
+ <docs-user></docs-user>
117
+ </div>
172
118
  </div>
173
119
  </template>
174
- </sonic-code>
120
+ </sonic-code>
@@ -1,150 +1,37 @@
1
- # Sharing data
1
+ # Legacy: Sharing data
2
2
 
3
- This section describes how we share data between graphical and non graphical components and classes.
3
+ > **New apps:** [Data flow](#docs/_core-concept/dataFlow.md/dataFlow) (`get` / `set` / `DataProviderKey`, decorators). This page documents the historical **Publisher** proxy API (`PublisherManager`, `publisher.set`, `onAssign`, …).
4
4
 
5
- Especialy, graphical components should not reference each other in order to **remain decoupled**.
6
-
7
- Thats why we use **publish/subscribe** paradigm to addresse this issue.
5
+ This section describes how data is shared between graphical and non-graphical components.
8
6
 
7
+ Graphical components should not reference each other directly — they stay decoupled via a **publish/subscribe** store.
9
8
 
10
9
  ## The Publisher
11
10
 
12
11
  ### Principle
13
12
 
14
- * The **publisher** is a [JavaScript proxy](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Proxy) that contains some data.<br>**
15
- Example of data : `{foo:{hello:["world"]}, bar:"baz"}`
16
-
17
- * if a property of the **publisher** (dot syntax / array access), it returns another **publisher**.
18
- Using the previous example `myPublisher.foo.hello` is also a publisher containing `["world"]`
13
+ * The **publisher** is a [JavaScript proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) that holds data.<br>
14
+ Example: `{foo:{hello:["world"]}, bar:"baz"}`
19
15
 
20
- * If the property doesn't exist at the time of the request, a publisher is created. its internal data is set to `null`.<br>
21
- The value that can then be provided later.
16
+ * Accessing a property (`myPublisher.foo.hello`) returns another **publisher** for that segment.
22
17
 
23
- * **Subscribers** can subscribe to the publisher's modifications and be updated in different ways (see : onAssign, onInternalMutation, startTemplateFilling).
18
+ * Missing properties create a publisher with internal data `null`, filled later.
24
19
 
25
- * Data inside the publisher is updated by modifying the publisher itself, for example `myPublisher.foo.hello = ["Joey", "Smith"]`
26
-
27
- * The publisher publishes modifications to any of its **Subscribers**.
20
+ * **Subscribers** listen via `onAssign`, `onInternalMutation`, template filling on the **Subscriber mixin**, etc.
28
21
 
22
+ * Updates use `publisher.set(...)` or nested assignment; changes propagate to subscribers.
29
23
 
30
- ❇️ The order of data creation and subscription theoretically has no importance.
24
+ ❇️ Order of creation vs subscription theoretically does not matter.
31
25
 
32
26
  ### Methods
33
27
 
34
- * **set (complete replacement):** Assign/modifies the internal value of the publisher.
35
- <sonic-code language="javascript">
36
- <template>
37
- publisher.set({foo:{hello:["world"]}, bar:"baz"});
38
- </template>
39
- </sonic-code>
40
- * **get:** Get the internal value of the publisher.
41
- <sonic-code language="javascript">
42
- <template>
43
- publisher.get() //{foo:{hello:["world"]}, bar:"baz"};
44
- </template>
45
- </sonic-code>
46
- * **onAssign/offAssign:** Subscribe/unsubscribe to value assignments (via `set`) of the publisher.
47
- <sonic-code language="javascript">
48
- <template>
49
- publisher.a.b.onAssign(console.log);
50
- //indirect
51
- publisher.a = {b:"dramatic change"}; //log: "dramatic change"
52
- //via set
53
- publisher.a.b.set(["Hello"]) //log: ["Hello"]
54
- </template>
55
- </sonic-code>
56
- * **onInternalMutation/offInternalMutation:** Listen to any internal mutation regardless of its depth level.
57
- <sonic-code language="javascript">
58
- <template>
59
- function save(){
60
- console.log("Something has changed, let's save");
61
- }
62
- publisher.onInternalMutation(save);
63
- publisher.a.b[0] = "e";
64
- </template>
65
- </sonic-code>
66
- * **startTemplateFilling/stopTemplateFilling:** Fill an object model, a principle used with the Subscriber mixin on which most Concorde components rely.
67
- <sonic-code language="javascript">
68
- <template>
69
- const fillableTemplate = { title: "A title to be replaced"};
70
- publisher.startTemplateFilling(fillableTemplate);
71
- state.title = "Good morning";
72
- publisher.stopTemplateFilling(fillableTemplate);
73
- state.title = "Oops";
74
- console.log(fillableTemplate);
75
- </template>
76
- </sonic-code>
77
- * **invalidate:** Flag the data as invalid. Used by sonic-fetch and sonic-list to trigger data reloading.
78
- <sonic-code language="javascript">
79
- <template>
80
- publisher.invalidate();
81
- </template>
82
- </sonic-code>
83
- * **onInvalidate/offInvalidate:** Subscribe/unsubscribe to data invalidation of the publisher. Used by sonic-fetch and sonic-list to trigger data reloading.
84
- <sonic-code language="javascript">
85
- <template>
86
- function reloadData(){
87
- console.log("Reload data to inject it again into the publisher");
88
- }
89
- publisher.onInvalidate(reloadData);
90
- </template>
91
- </sonic-code>
92
-
93
- ## DataProvider
94
-
95
- Denotes the identifier of a publisher as referenced in the PublisherManager (see below).
96
- Uses the dataProvider attribut in html tags to scop the content with some data.
97
- see [Subscribers](#docs/_core-concept/subscriber.md/subscriber).
98
-
99
-
100
- ## PublisherManager
101
-
102
- The **PublisherManager** is a utility class to get publishers
103
-
104
- It plays a central role in the components, especially through the "subscriber" mixin.<br>
105
- Automatic data communication between components in concorde uses this principle in conjunction with Lit's reactive properties. <br>
106
- Refer to the documentation for [Subscriber](#docs/_core-concept/subscriber.md/subscriber).
107
-
108
- <sonic-code language="javascript">
109
- <template>
110
- import { PublisherManager } from "publisherproxy";
111
- let dataProvider = "cart";
112
- let publisher = PublisherManager.get(dataProvider);
113
-
114
- </template>
115
- </sonic-code>
116
-
117
- It is declared on the `window` object to allow usage in a web page, so the equivalent one-liner would be:
118
-
119
- <sonic-code language="javascript">
120
- <template>
121
- let dataProvider = "cart";
122
- let publisher = SonicPublisherManager.get(dataProvider);
123
-
124
- </template>
125
- </sonic-code>
126
-
127
-
128
- ## Basic Example
129
-
130
- This example can be tested in a console when Concorde is loaded on the page (for example, in a ticketing system).
131
- In a component, you will need to perform an `import` as explained earlier.
132
-
133
- <sonic-code language="javascript">
134
- <template>
135
- // Anywhere, anytime
136
- SonicPublisherManager.get("mySubject").title.onAssign(console.log)
137
-
138
- </template>
139
- </sonic-code>
140
-
141
- <sonic-code language="javascript">
142
- <template>
143
- // Anywhere, anytime
144
- let publisher = SonicPublisherManager.get("mySubject");
145
- // ...
146
- publisher.set({title: "A title"});
147
- publisher.title.set("A second title");
148
-
149
- </template>
150
- </sonic-code>
28
+ * **set** replace internal value
29
+ <sonic-code language="javascript"><template>publisher.set({foo:{hello:["world"]}, bar:"baz"});</template></sonic-code>
30
+
31
+ * **get** — read internal value
32
+ <sonic-code language="javascript"><template>publisher.get()</template></sonic-code>
33
+
34
+ * **onAssign / offAssign** react to `set`
35
+ <sonic-code language="javascript"><template>publisher.a.b.onAssign(console.log);</template></sonic-code>
36
+
37
+ Modern equivalent: `get` / `set` / `@handle` — see [Data flow](#docs/_core-concept/dataFlow.md/dataFlow).