@nebulahome/package-sdk 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  The SDK's version is the version of the package API the platform implements: a minor version adds
4
4
  to it, a major one breaks it, and a patch leaves it as it is.
5
5
 
6
+ ## 1.1.0
7
+
8
+ - `useTranslation()` in `@nebulahome/package-sdk/ui`: a package's page, cards and entity views
9
+ say their strings with `t('clients.title', 'Clients')`, in the viewer's language. The English
10
+ is the fallback, and a plural takes `{ one, other }` with `count`; outside the interface - a
11
+ component's unit test - every string is its English.
12
+ - Catalogues: `locales/<language>.json` beside `nebula.config.ts` (`it.json`, `pt-BR.json`), JSON
13
+ objects of strings nested as the keys are dotted, with i18next's plural suffixes and
14
+ `{{placeholders}}`. `nebula()` bundles each as a chunk of the interface, loaded only for a viewer
15
+ who reads that language; `validate` checks them (a language for a name, strings only, plurals
16
+ with their `_other`, at most 256 KB); `build` warns which strings a catalogue says in English
17
+ and which of its keys no string uses.
18
+ - What `nebula.config.ts` declares - names, settings, entity types - stays English, as the
19
+ platform shows it everywhere.
20
+
21
+ ## 1.0.1
22
+
23
+ - `nebulahome-package --help`, and a mistyped command, work where Vite is not installed -
24
+ `npx -p @nebulahome/package-sdk nebulahome-package --help` in an empty folder. `validate`,
25
+ `build` and `pack` run without it say what to install in the package's folder, instead of
26
+ failing with `ERR_MODULE_NOT_FOUND`.
27
+
6
28
  ## 1.0.0
7
29
 
8
30
  The first public release.
package/README.md CHANGED
@@ -86,17 +86,47 @@ import { nebula } from '@nebulahome/package-sdk/vite';
86
86
  export default defineConfig({ plugins: [react(), tailwindcss(), nebula()] });
87
87
  ```
88
88
 
89
+ ## Translating the interface
90
+
91
+ The page, the cards and the entity views say their strings through `useTranslation()`, with the
92
+ English beside each key; a catalogue per language goes in `locales/` next to `nebula.config.ts`:
93
+
94
+ ```tsx
95
+ // src/ui/forecast-card.tsx
96
+ import { useTranslation } from '@nebulahome/package-sdk/ui';
97
+
98
+ const { t } = useTranslation();
99
+
100
+ t('forecast.empty', 'No forecast yet');
101
+ t('forecast.days', { one: '{{count}} day', other: '{{count}} days' }, { count: days.length });
102
+ ```
103
+
104
+ ```json
105
+ // locales/it.json
106
+ {
107
+ "forecast": {
108
+ "empty": "Ancora nessuna previsione",
109
+ "days_one": "{{count}} giorno",
110
+ "days_other": "{{count}} giorni"
111
+ }
112
+ }
113
+ ```
114
+
115
+ A string a catalogue lacks is said in English, and `nebulahome-package build` lists them. What
116
+ `nebula.config.ts` declares (the package's name, its cards' and settings' names, its entity types)
117
+ stays English: the platform shows it the same way to everyone.
118
+
89
119
  ## Entry points
90
120
 
91
- | Import | What |
92
- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
93
- | `@nebulahome/package-sdk` | `definePackage`, `defineSettings`, `defineCard`, `defineEntityType`, `definePage`, `defineContainer`, `defineCompose`, `field`, entity id helpers, `SDK_VERSION`, the value types. |
94
- | `/server` | `defineServer`, and the context `start` is given: settings (live or restart), devices and entities, typed custom entities, the rest of the house, methods for the interface, services between packages. |
95
- | `/ui` | The props of a page, a card and an entity view; hooks for the package, its methods, its settings, the house, the viewer, the theme; navigation inside the package's page and to the platform's places. |
96
- | `/components` | The part of the interface's design system a package may draw with. |
97
- | `/vite` | `nebula()`, the Vite plugin that builds both halves: the interface in chunks with its CSS scoped to the package, the server bundled whole. |
98
- | `/testing` | `createTestContext()`: run `start` in a unit test, every effect recorded. |
99
- | `/styles.css` | The interface's Tailwind tokens, to `@reference`. |
121
+ | Import | What |
122
+ | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123
+ | `@nebulahome/package-sdk` | `definePackage`, `defineSettings`, `defineCard`, `defineEntityType`, `definePage`, `defineContainer`, `defineCompose`, `field`, entity id helpers, `SDK_VERSION`, the value types. |
124
+ | `/server` | `defineServer`, and the context `start` is given: settings (live or restart), devices and entities, typed custom entities, the rest of the house, methods for the interface, services between packages. |
125
+ | `/ui` | The props of a page, a card and an entity view; hooks for the package, its methods, its settings, the house, the viewer, the theme, its strings; navigation inside the package's page and the platform's. |
126
+ | `/components` | The part of the interface's design system a package may draw with. |
127
+ | `/vite` | `nebula()`, the Vite plugin that builds both halves: the interface in chunks with its CSS scoped to the package, the server bundled whole. |
128
+ | `/testing` | `createTestContext()`: run `start` in a unit test, every effect recorded. |
129
+ | `/styles.css` | The interface's Tailwind tokens, to `@reference`. |
100
130
 
101
131
  The `nebulahome-package` command checks, builds and packs a package:
102
132
 
@@ -23,15 +23,16 @@ function hostSdkVersion() {
23
23
  return typeof version === "string" ? version : void 0;
24
24
  }
25
25
  /**
26
- * One member of a module the interface lends.
26
+ * One member of a module the interface lends, when it lends it.
27
+ *
28
+ * For a member with a way of its own to do without the interface - `useTranslation` says the
29
+ * English - where {@link hostMember} would refuse.
27
30
  *
28
31
  * @param module - The module's key.
29
32
  * @param name - The member.
30
- * @param since - The SDK version that added it.
31
- * @returns The interface's implementation of it.
32
- * @throws {Error} When there is no interface, or it does not implement the member.
33
+ * @returns The interface's implementation of it, or undefined when there is none.
33
34
  */
34
- function hostMember(module, name, since) {
35
+ function lentMember(module, name) {
35
36
  const nebula = Reflect.get(globalThis, "__nebula");
36
37
  const modules = isRecord(nebula) ? nebula["modules"] : void 0;
37
38
  const lent = isRecord(modules) ? modules[module] : void 0;
@@ -45,9 +46,22 @@ function hostMember(module, name, since) {
45
46
  * @returns True when it can be called or drawn.
46
47
  */
47
48
  const isLent = (value) => typeof value === "function" || isRecord(value) && "$$typeof" in value;
48
- if (isLent(member)) return member;
49
+ return isLent(member) ? member : void 0;
50
+ }
51
+ /**
52
+ * One member of a module the interface lends.
53
+ *
54
+ * @param module - The module's key.
55
+ * @param name - The member.
56
+ * @param since - The SDK version that added it.
57
+ * @returns The interface's implementation of it.
58
+ * @throws {Error} When there is no interface, or it does not implement the member.
59
+ */
60
+ function hostMember(module, name, since) {
61
+ const member = lentMember(module, name);
62
+ if (member !== void 0) return member;
49
63
  const version = hostSdkVersion();
50
64
  throw new Error(version === void 0 ? `${name} is lent by the NebulaHome interface, and there is none here` : `${name} needs package SDK ${since}; this interface implements ${version}`);
51
65
  }
52
66
  //#endregion
53
- export { UI_MODULE as n, hostMember as r, COMPONENTS_MODULE as t };
67
+ export { lentMember as i, UI_MODULE as n, hostMember as r, COMPONENTS_MODULE as t };