@supersoniks/concorde 4.6.0 → 4.7.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/.gitlab-ci.yml +23 -0
- package/README.md +106 -55
- package/ai/AGENTS.md +52 -0
- package/ai/README.md +30 -0
- package/ai/cursor/rules/concorde-menu.mdc +15 -0
- package/ai/cursor/rules/concorde-scope.mdc +14 -0
- package/ai/cursor/rules/concorde-theme.mdc +13 -0
- package/ai/cursor/rules/concorde.mdc +49 -0
- package/ai/jetbrains/rules/concorde.md +39 -0
- package/ai/skills/concorde/SKILL.md +220 -0
- package/ai/skills/concorde-get-set-dp/SKILL.md +194 -0
- package/ai/skills/concorde-imports/SKILL.md +78 -0
- package/ai/skills/concorde-menu/SKILL.md +74 -0
- package/ai/skills/concorde-scope/SKILL.md +70 -0
- package/ai/skills/concorde-theme/SKILL.md +46 -0
- package/build-infos.json +1 -1
- package/concorde-core.bundle.js +127 -127
- package/concorde-core.es.js +1435 -1364
- package/dist/altcha-widget.js +2662 -0
- package/dist/concorde-core.bundle.js +127 -127
- package/dist/concorde-core.es.js +1435 -1364
- package/dist/docs-mock-api-sw.js +589 -0
- package/dist/docs-mock-api-sw.js.map +7 -0
- package/docs/altcha-widget.js +2662 -0
- package/docs/assets/index-D9pxaQYK.js +7508 -0
- package/docs/assets/index-t0-i22oI.css +1 -0
- package/docs/docs-mock-api-sw.js +589 -0
- package/docs/docs-mock-api-sw.js.map +7 -0
- package/docs/index.html +2 -2
- package/docs/src/core/components/functional/fetch/fetch.md +13 -11
- package/docs/src/core/components/functional/if/if.md +4 -11
- package/docs/src/core/components/functional/list/list.md +60 -194
- package/docs/src/core/components/functional/queue/queue.md +70 -85
- package/docs/src/core/components/functional/router/router.md +62 -97
- package/docs/src/core/components/functional/states/states.md +2 -2
- package/docs/src/core/components/functional/submit/submit.md +86 -55
- package/docs/src/core/components/ui/captcha/captcha.md +2 -2
- package/docs/src/core/components/ui/card/card.md +1 -1
- package/docs/src/core/components/ui/form/checkbox/checkbox.md +5 -32
- package/docs/src/core/components/ui/form/input/input.md +5 -30
- package/docs/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +6 -4
- package/docs/src/core/components/ui/form/radio/radio.md +5 -32
- package/docs/src/core/components/ui/form/select/select.md +5 -31
- package/docs/src/core/components/ui/form/switch/switch.md +5 -32
- package/docs/src/core/components/ui/loader/loader.md +1 -13
- package/docs/src/core/components/ui/table/table.md +3 -3
- package/docs/src/docs/_core-concept/dataFlow.md +73 -0
- package/docs/src/docs/_core-concept/subscriber.md +9 -10
- package/docs/src/docs/_decorators/ancestor-attribute.md +4 -3
- package/docs/src/docs/_decorators/auto-subscribe.md +19 -16
- package/docs/src/docs/_decorators/bind.md +20 -17
- package/docs/src/docs/_decorators/get.md +7 -4
- package/docs/src/docs/_decorators/handle.md +171 -0
- package/docs/src/docs/_decorators/on-assign.md +99 -73
- package/docs/src/docs/_decorators/publish.md +2 -1
- package/docs/src/docs/_decorators/subscribe.md +70 -9
- package/docs/src/docs/_decorators/wait-for-ancestors.md +13 -10
- package/docs/src/docs/_directives/sub.md +91 -0
- package/docs/src/docs/_getting-started/ai-agents.md +56 -0
- package/docs/src/docs/_getting-started/concorde-manual-install.md +133 -0
- package/docs/src/docs/_getting-started/concorde-outside.md +13 -123
- package/docs/src/docs/_getting-started/create-a-component.md +2 -0
- package/docs/src/docs/_getting-started/my-first-component.md +236 -0
- package/docs/src/docs/_getting-started/my-first-subscriber.md +29 -83
- package/docs/src/docs/_getting-started/pubsub.md +21 -134
- package/docs/src/docs/_getting-started/start.md +26 -18
- package/docs/src/docs/_misc/api-configuration.md +79 -0
- package/docs/src/docs/_misc/dataProviderKey.md +38 -5
- package/docs/src/docs/_misc/docs-mock-api.md +60 -0
- package/docs/src/docs/_misc/endpoint.md +2 -1
- package/docs/src/docs/_misc/html-integration.md +13 -0
- package/docs/src/docs/search/docs-search.json +4163 -873
- package/docs/src/tsconfig.json +380 -317
- package/gitlab/job_tests.sh +55 -0
- package/package.json +34 -3
- package/public/altcha-widget.js +2662 -0
- package/public/docs-mock-api-sw.js +589 -0
- package/public/docs-mock-api-sw.js.map +7 -0
- package/scripts/ai-init.mjs +167 -0
- package/scripts/docs-mock-api-vite-plugin.ts +116 -0
- package/scripts/docs-open-in-editor-plugin.ts +130 -0
- package/scripts/pre-publish.mjs +2 -1
- package/src/core/components/functional/example/example.ts +1 -1
- package/src/core/components/functional/fetch/fetch.md +13 -11
- package/src/core/components/functional/if/if.md +4 -11
- package/src/core/components/functional/list/list.demo.ts +4 -4
- package/src/core/components/functional/list/list.md +60 -194
- package/src/core/components/functional/list/list.ts +8 -7
- package/src/core/components/functional/queue/queue.demo.ts +1 -1
- package/src/core/components/functional/queue/queue.md +70 -85
- package/src/core/components/functional/queue/queue.ts +4 -4
- package/src/core/components/functional/router/router.md +62 -97
- package/src/core/components/functional/router/router.ts +1 -1
- package/src/core/components/functional/states/states.md +2 -2
- package/src/core/components/functional/submit/submit.md +86 -55
- package/src/core/components/functional/submit/submit.ts +10 -3
- package/src/core/components/ui/captcha/captcha.md +2 -2
- package/src/core/components/ui/card/card.md +1 -1
- package/src/core/components/ui/form/checkbox/checkbox.md +5 -32
- package/src/core/components/ui/form/input/input.md +5 -30
- package/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +6 -4
- package/src/core/components/ui/form/radio/radio.md +5 -32
- package/src/core/components/ui/form/select/select.md +5 -31
- package/src/core/components/ui/form/switch/switch.md +5 -32
- package/src/core/components/ui/loader/loader.md +1 -13
- package/src/core/components/ui/table/table.md +3 -3
- package/src/core/directives/DataProvider.sub.spec.ts +96 -0
- package/src/core/directives/DataProvider.ts +109 -40
- package/src/core/utils/PublisherProxy.ts +33 -18
- package/src/core/utils/dataProviderKey.ts +23 -0
- package/src/core/utils/publisherPathKey.spec.ts +58 -0
- package/src/docs/_core-concept/dataFlow.md +73 -0
- package/src/docs/_core-concept/subscriber.md +9 -10
- package/src/docs/_decorators/ancestor-attribute.md +4 -3
- package/src/docs/_decorators/auto-subscribe.md +19 -16
- package/src/docs/_decorators/bind.md +19 -16
- package/src/docs/_decorators/get.md +7 -4
- package/src/docs/_decorators/handle.md +15 -13
- package/src/docs/_decorators/on-assign.md +53 -53
- package/src/docs/_decorators/publish.md +2 -1
- package/src/docs/_decorators/subscribe.md +70 -9
- package/src/docs/_decorators/wait-for-ancestors.md +13 -10
- package/src/docs/_directives/sub.md +91 -0
- package/src/docs/_getting-started/ai-agents.md +56 -0
- package/src/docs/_getting-started/concorde-manual-install.md +133 -0
- package/src/docs/_getting-started/concorde-outside.md +13 -123
- package/src/docs/_getting-started/create-a-component.md +2 -0
- package/src/docs/_getting-started/my-first-component.md +236 -0
- package/src/docs/_getting-started/my-first-subscriber.md +29 -83
- package/src/docs/_getting-started/pubsub.md +21 -134
- package/src/docs/_getting-started/start.md +26 -18
- package/src/docs/_misc/api-configuration.md +79 -0
- package/src/docs/_misc/dataProviderKey.md +34 -1
- package/src/docs/_misc/docs-mock-api.md +60 -0
- package/src/docs/_misc/endpoint.md +2 -1
- package/src/docs/_misc/html-integration.md +13 -0
- package/src/docs/code.ts +58 -12
- package/src/docs/components/docs-demo-sources.ts +397 -0
- package/src/docs/components/docs-lit-demo-raw.ts +28 -0
- package/src/docs/components/docs-lit-demo.ts +166 -0
- package/src/docs/components/docs-source-link.ts +72 -0
- package/src/docs/docs-location.ts +54 -0
- package/src/docs/docs.ts +12 -0
- package/src/docs/example/decorators-demo-bind-demos.ts +41 -46
- package/src/docs/example/decorators-demo-geo.ts +16 -11
- package/src/docs/example/decorators-demo-init.ts +2 -228
- package/src/docs/example/decorators-demo-subscribe-publish-get-demos.ts +54 -14
- package/src/docs/example/decorators-demo.ts +71 -70
- package/src/docs/example/docs-api-config-demos.ts +234 -0
- package/src/docs/example/docs-joke-demos.ts +297 -0
- package/src/docs/example/docs-list-demos.ts +179 -0
- package/src/docs/example/docs-provider-keys.ts +315 -0
- package/src/docs/example/docs-queue-demos.ts +114 -0
- package/src/docs/example/docs-router-demos.ts +89 -0
- package/src/docs/example/docs-submit-demos.ts +455 -0
- package/src/docs/example/docs-toggle-demos.ts +73 -0
- package/src/docs/example/docs-user-two-scopes.ts +37 -0
- package/src/docs/example/docs-users-list.ts +71 -0
- package/src/docs/example/users.ts +41 -24
- package/src/docs/mock-api/api-config-mock.ts +152 -0
- package/src/docs/mock-api/fixtures.ts +377 -0
- package/src/docs/mock-api/register.ts +25 -0
- package/src/docs/mock-api/router.ts +234 -0
- package/src/docs/mock-api/service-worker.ts +23 -0
- package/src/docs/mock-api/urls.ts +11 -0
- package/src/docs/navigation/navigation.ts +39 -7
- package/src/docs/search/docs-search.json +4021 -936
- package/src/docs/search/markdown-renderer.ts +7 -3
- package/src/docs/search/page.ts +11 -14
- package/src/docs/search/sonic-code-markdown.spec.ts +29 -0
- package/src/docs/search/sonic-code-markdown.ts +28 -0
- package/src/docs.ts +4 -0
- package/src/tsconfig.json +87 -0
- package/src/tsconfig.tsbuildinfo +1 -1
- package/vite.config.mts +8 -0
- package/docs/assets/index-CaysOMFz.js +0 -5046
- package/docs/assets/index-D8mGoXzF.css +0 -1
- package/docs/src/docs/_misc/templates-demo.md +0 -19
- 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`<div class="flex items-center gap-3 rounded-md p-2">
|
|
39
|
+
<sonic-image src=${this.avatar} rounded="md" ratio="1/1" class="w-16"></sonic-image>
|
|
40
|
+
<div>
|
|
41
|
+
<div>${this.first_name} <span class="font-bold">${this.last_name}</span></div>
|
|
42
|
+
<div class="text-sm text-neutral-400">${this.email}</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>`;
|
|
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<
|
|
78
|
+
DocsUserData,
|
|
79
|
+
{ dataProvider: string | null }
|
|
80
|
+
>("${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`<div class="flex items-center gap-3 rounded-md p-2">
|
|
127
|
+
<sonic-image src=${u.avatar} rounded="md" ratio="1/1" class="w-16"></sonic-image>
|
|
128
|
+
<div>
|
|
129
|
+
<div>${u.first_name} <span class="font-bold">${u.last_name}</span></div>
|
|
130
|
+
<div class="text-sm text-neutral-400">${u.email}</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>`;
|
|
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
|
+
<div class="grid md:grid-cols-2 gap-6">
|
|
156
|
+
<div dataProvider="${docsUserScopeAKey.path}">
|
|
157
|
+
<docs-user></docs-user>
|
|
158
|
+
</div>
|
|
159
|
+
<div dataProvider="${docsUserScopeBKey.path}">
|
|
160
|
+
<docs-user></docs-user>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
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
|
+
<div class="flex gap-3">
|
|
191
|
+
<sonic-image src=${avatar} ...></sonic-image>
|
|
192
|
+
<div>${first_name} <b>${last_name}</b></div>
|
|
193
|
+
<div class="text-sm text-neutral-400">${email}</div>
|
|
194
|
+
</div>
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
render() {
|
|
198
|
+
return html`
|
|
199
|
+
<sonic-list fetch dataProvider=${usersListEndpoint.path} key="data" .items=${this.items}></sonic-list>
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
24
|
-
${this.first_name} ${this.last_name}
|
|
21
|
+
<img src="${this.avatar}" /> <br>
|
|
22
|
+
${this.first_name} ${this.last_name} <br>
|
|
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
|
|
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
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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`<div class="flex items-center gap-3 p-2">
|
|
56
|
+
<sonic-image src=${this.avatar} rounded="md" ratio="1/1" class="w-16"></sonic-image>
|
|
57
|
+
<div>${this.first_name} <span class="font-bold">${this.last_name}</span></div>
|
|
58
|
+
<div class="text-sm text-neutral-400">${this.email}</div>
|
|
59
|
+
</div>`;
|
|
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
|
-
|
|
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="
|
|
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="
|
|
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"
|
|
163
|
-
<sonic-input label="Last name" type="text" name="last_name"
|
|
164
|
-
<sonic-input class="col-span-2"
|
|
165
|
-
<sonic-input type="
|
|
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
|
-
<
|
|
169
|
-
<
|
|
170
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/
|
|
15
|
-
Example
|
|
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
|
-
*
|
|
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
|
-
*
|
|
18
|
+
* Missing properties create a publisher with internal data `null`, filled later.
|
|
24
19
|
|
|
25
|
-
*
|
|
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
|
-
❇️
|
|
24
|
+
❇️ Order of creation vs subscription theoretically does not matter.
|
|
31
25
|
|
|
32
26
|
### Methods
|
|
33
27
|
|
|
34
|
-
* **set
|
|
35
|
-
<sonic-code language="javascript">
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
* **
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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).
|