@morlay/dsh-client-ui-primitives 0.0.7 → 0.0.8

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 (67) hide show
  1. package/README.md +29 -5
  2. package/dist/client.d.mts +186 -11201
  3. package/dist/client.mjs +981 -1827
  4. package/package.json +5 -7
  5. package/src/client/controls/Bubble.module.css +17 -0
  6. package/src/client/controls/Bubble.tsx +17 -0
  7. package/src/client/controls/Button.module.css +10 -0
  8. package/src/client/controls/Button.tsx +29 -0
  9. package/src/client/controls/DisclosureRow.module.css +22 -0
  10. package/src/client/controls/DisclosureRow.tsx +20 -0
  11. package/src/client/controls/IconButton.module.css +50 -0
  12. package/src/client/controls/IconButton.tsx +45 -0
  13. package/src/client/controls/ModelRouteList.module.css +100 -0
  14. package/src/client/controls/ModelRouteList.tsx +118 -0
  15. package/src/client/controls/MultilineField.module.css +26 -0
  16. package/src/client/controls/MultilineField.tsx +19 -0
  17. package/src/client/controls/SearchInput.module.css +11 -0
  18. package/src/client/controls/SearchInput.tsx +22 -0
  19. package/src/client/controls/SearchSelect.module.css +34 -0
  20. package/src/client/controls/SearchSelect.tsx +138 -0
  21. package/src/client/controls/SeatButton.module.css +53 -0
  22. package/src/client/controls/SeatButton.tsx +40 -0
  23. package/src/client/controls/Spinner.module.css +18 -0
  24. package/src/client/controls/Spinner.tsx +14 -0
  25. package/src/client/controls/Tabs.module.css +48 -0
  26. package/src/client/controls/Tabs.tsx +57 -0
  27. package/src/client/controls/TagInput.module.css +105 -0
  28. package/src/client/controls/TagInput.tsx +152 -0
  29. package/src/client/controls/TimeLabel.module.css +16 -0
  30. package/src/client/controls/TimeLabel.tsx +15 -0
  31. package/src/client/controls/VisuallyHidden.module.css +9 -0
  32. package/src/client/controls/VisuallyHidden.tsx +16 -0
  33. package/src/client/controls/classes.ts +7 -0
  34. package/src/client/controls/index.ts +30 -0
  35. package/src/client/controls/tags.ts +24 -0
  36. package/src/client/index.ts +10 -2
  37. package/src/client/layout/Row.tsx +86 -0
  38. package/src/client/layout/Stack.tsx +79 -0
  39. package/src/client/layout/Text.tsx +54 -0
  40. package/src/client/layout/index.ts +16 -0
  41. package/src/client/layout/layout.module.css +217 -0
  42. package/src/client/layout/scales.ts +91 -0
  43. package/src/client/schema-form/Editor.tsx +48 -65
  44. package/src/client/schema-form/SchemaForm.tsx +4 -4
  45. package/src/client/schema-form/controller.ts +5 -2
  46. package/src/client/schema-form/geometry.ts +3 -0
  47. package/src/client/schema-form/schema-form.module.css +335 -0
  48. package/src/client/schema-form/value.tsx +10 -9
  49. package/src/client/settings-form/SettingsFieldRow.module.css +93 -0
  50. package/src/client/settings-form/SettingsFieldRow.tsx +103 -0
  51. package/src/client/settings-form/index.ts +5 -18
  52. package/src/css-modules.d.ts +6 -0
  53. package/src/client/schema-form/styles.ts +0 -321
  54. package/src/client/settings-form/SettingsForm.styles.ts +0 -58
  55. package/src/client/settings-form/SettingsForm.tsx +0 -68
  56. package/src/client/settings-form/fields.styles.ts +0 -158
  57. package/src/client/settings-form/fields.tsx +0 -184
  58. package/src/client/settings-form/form-model.ts +0 -339
  59. package/src/client/styling/css.ts +0 -27
  60. package/src/client/styling/focus.ts +0 -9
  61. package/src/client/styling/index.ts +0 -6
  62. package/src/client/styling/styled.tsx +0 -54
  63. package/src/client/styling/styling.ts +0 -142
  64. package/src/client/styling/token.ts +0 -275
  65. package/src/client/styling/toolkit.ts +0 -37
  66. package/src/client/theme.generated.ts +0 -846
  67. package/src/client/theme.ts +0 -5
@@ -1,275 +0,0 @@
1
- import type { CSSProps, CSSValue } from "./css.ts";
2
- import {
3
- isFunction,
4
- isNull,
5
- isPlainObject,
6
- isString,
7
- isUndefined,
8
- mapKeys,
9
- toMerged,
10
- } from "./toolkit.ts";
11
-
12
- const cssVarSymbol = Symbol("cssVar");
13
- const tokensSymbol = Symbol("tokens");
14
- const tokenInstSymbol = Symbol("tokenInst");
15
-
16
- export interface CSSVarRef {
17
- (): Iterable<string>;
18
- toString(): string;
19
- [Symbol.toPrimitive](hint: string): string;
20
- }
21
-
22
- export type TokenVars<T> = (T extends string | true
23
- ? CSSVarRef
24
- : { readonly [K in keyof T]: TokenVars<T[K]> }) &
25
- CSSVarRef;
26
-
27
- export type Tokens = Record<string, unknown>;
28
-
29
- const SELF = "$";
30
-
31
- function tokenVars<T extends Tokens>(token: Token, tokens: T, path: string[]): TokenVars<T> {
32
- const reserved = new Set(["constructor", "toJSON", "__proto__"]);
33
-
34
- return new Proxy(() => {}, {
35
- apply() {
36
- return Token.fallbackVar(token.cssVar(path));
37
- },
38
- get(_target, property) {
39
- if (
40
- property === Symbol.toPrimitive ||
41
- property === Symbol.toStringTag ||
42
- property === "toString"
43
- ) {
44
- return () => `var(${token.cssVar(path)})`;
45
- }
46
- if (property === "valueOf") return () => Token.fallbackVar(token.cssVar(path));
47
- if (property === tokenInstSymbol) return token;
48
- if (property === tokensSymbol) return tokens;
49
- if (property === cssVarSymbol) return token.cssVar(path);
50
- if (!isString(property) || reserved.has(property)) return undefined;
51
- const next = (tokens as Record<string, unknown>)[property];
52
- if (isUndefined(next)) return undefined;
53
- return tokenVars(token, next as Tokens, [...path, property]);
54
- },
55
- }) as unknown as TokenVars<T>;
56
- }
57
-
58
- export class Token {
59
- static vars<T extends Tokens>(tokens: T, options: { prefix?: string } = {}): TokenVars<T> {
60
- return tokenVars<T>(new Token(options.prefix ?? ""), tokens, []);
61
- }
62
-
63
- static extendsVars<T extends Tokens, E extends Tokens>(
64
- vars: TokenVars<T>,
65
- extra: E,
66
- ): TokenVars<T & E> {
67
- const tokens = (vars as unknown as Record<symbol, unknown>)[tokensSymbol] ?? {};
68
- return Token.vars(toMerged(tokens, extra) as T & E);
69
- }
70
-
71
- static assignVars<T extends Tokens>(
72
- vars: TokenVars<T>,
73
- overwrites?: Partial<T>,
74
- ): Record<`--${string}`, CSSValue> {
75
- const tokens = (overwrites ??
76
- (vars as unknown as Record<symbol, unknown>)[tokensSymbol] ??
77
- {}) as T;
78
- const token =
79
- ((vars as unknown as Record<symbol, unknown>)[tokenInstSymbol] as Token | undefined) ??
80
- new Token("");
81
-
82
- const result: Record<string, CSSValue> = {};
83
- for (const [name, value] of flattenTokens(token, tokens, []))
84
- result[name] = token.normalize(value);
85
- return result as Record<`--${string}`, CSSValue>;
86
- }
87
-
88
- static variants(variants: Record<string, CSSProps>): Record<string, CSSProps> {
89
- return mapKeys(variants, (key) => `&[data-variant="${key}"]`) as Record<string, CSSProps>;
90
- }
91
-
92
- static val<T extends string | number = string>(
93
- strings: TemplateStringsArray,
94
- ...values: CSSValue<T>[]
95
- ): () => Iterable<T> {
96
- return function* (): Iterable<T> {
97
- for (let index = 0; index < strings.length; index += 1) {
98
- const literal = strings[index];
99
- if (literal) yield literal as T;
100
- if (index >= values.length) continue;
101
- const value = values[index];
102
- yield* isFunction(value) ? value() : [value as T];
103
- }
104
- };
105
- }
106
-
107
- static calc<T extends string | number = string>(
108
- strings: TemplateStringsArray,
109
- ...values: CSSValue<T>[]
110
- ): () => Iterable<T> {
111
- return combinator("calc(", ")", strings, values);
112
- }
113
-
114
- static min<T extends string | number = string>(
115
- strings: TemplateStringsArray,
116
- ...values: CSSValue<T>[]
117
- ): () => Iterable<T> {
118
- return combinator("min(", ")", strings, values);
119
- }
120
-
121
- static max<T extends string | number = string>(
122
- strings: TemplateStringsArray,
123
- ...values: CSSValue<T>[]
124
- ): () => Iterable<T> {
125
- return combinator("max(", ")", strings, values);
126
- }
127
-
128
- static url<T extends string | number = string>(
129
- strings: TemplateStringsArray,
130
- ...values: CSSValue<T>[]
131
- ): () => Iterable<T> {
132
- return combinator("url(", ")", strings, values);
133
- }
134
-
135
- static colorMix<T extends string | number = string>(
136
- strings: TemplateStringsArray,
137
- ...values: CSSValue<T>[]
138
- ): () => Iterable<T> {
139
- return combinator("color-mix(", ")", strings, values);
140
- }
141
-
142
- static colorScale(
143
- color: CSSValue<string>,
144
- options: {
145
- alpha?: CSSValue<number>;
146
- lightness?: CSSValue<number>;
147
- saturation?: CSSValue<number>;
148
- whiteness?: CSSValue<number>;
149
- blackness?: CSSValue<number>;
150
- } = {},
151
- ): CSSValue<string> {
152
- const channel = (
153
- name: string,
154
- amount: CSSValue<number>,
155
- max: number,
156
- ): (() => Iterable<string>) =>
157
- Token.calc<string>`${name as unknown as string} + (${String(max)} - ${name as unknown as string}) * max(${amount as unknown as CSSValue<string>}, 0) + ${name as unknown as string} * min(${amount as unknown as CSSValue<string>}, 0)`;
158
- const mix = (
159
- from: CSSValue<string>,
160
- to: CSSValue<string>,
161
- amount: CSSValue<number>,
162
- ): (() => Iterable<string>) =>
163
- Token.colorMix<string>`in srgb, ${from}, ${to} ${Token.calc<string>`${amount as unknown as CSSValue<string>} * 100%`}`;
164
-
165
- let result: CSSValue<string> = color;
166
- if (
167
- !isUndefined(options.alpha) ||
168
- !isUndefined(options.lightness) ||
169
- !isUndefined(options.saturation)
170
- ) {
171
- result = Token.val<string>`hsl(from ${result} h ${
172
- isUndefined(options.saturation)
173
- ? ("s" as unknown as CSSValue<string>)
174
- : channel("s", options.saturation, 100)
175
- } ${isUndefined(options.lightness) ? ("l" as unknown as CSSValue<string>) : channel("l", options.lightness, 100)} / ${
176
- isUndefined(options.alpha)
177
- ? ("alpha" as unknown as CSSValue<string>)
178
- : channel("alpha", options.alpha, 1)
179
- })`;
180
- }
181
- if (!isUndefined(options.whiteness)) result = mix(result, "white", options.whiteness);
182
- if (!isUndefined(options.blackness)) result = mix(result, "black", options.blackness);
183
- return result;
184
- }
185
-
186
- static fallbackVar<T extends string | number = string>(
187
- value: CSSValue<T>,
188
- ...fallbacks: CSSValue<T>[]
189
- ): CSSValue<T> {
190
- return Object.assign(
191
- function* (): Iterable<T> {
192
- yield "var(" as T;
193
- for (const [index, item] of [value, ...fallbacks].entries()) {
194
- if (index > 0) yield ", " as T;
195
- yield* asIterable(item);
196
- }
197
- yield ")" as T;
198
- },
199
- { [cssVarSymbol]: value },
200
- );
201
- }
202
-
203
- static collect<T extends string | number>(value: Iterable<T> | (() => Iterable<T>)): string {
204
- const iterable = isFunction(value) ? value() : value;
205
- let result = "";
206
- for (const item of iterable) result += `${item}`;
207
- return result;
208
- }
209
-
210
- constructor(public readonly prefix: string = "") {}
211
-
212
- prop = (key: string): string => (key.startsWith("--") ? key : kebabCase(key));
213
-
214
- normalize = (input: unknown): string => {
215
- const value = isFunction(input) ? input() : input;
216
- if (typeof value === "number") return `${value}`;
217
- if (typeof value === "string") return value;
218
- if (isUndefined(value) || isNull(value)) return "";
219
-
220
- if (isFunction(value)) return Token.collect(value as () => Iterable<string | number>);
221
- if (isPlainObject(value) && Symbol.iterator in value)
222
- return Token.collect(value as Iterable<string | number>);
223
- return "";
224
- };
225
-
226
- cssVar = (paths: readonly string[]): string =>
227
- `--${[this.prefix, ...paths].filter(Boolean).join("-")}`;
228
- }
229
-
230
- function combinator<T extends string | number>(
231
- open: string,
232
- close: string,
233
- strings: TemplateStringsArray,
234
- values: CSSValue<T>[],
235
- ): () => Iterable<T> {
236
- return function* (): Iterable<T> {
237
- yield open as T;
238
- yield* Token.val<T>(strings, ...values)();
239
- yield close as T;
240
- };
241
- }
242
-
243
- function* asIterable<T extends string | number>(value: CSSValue<T>): Iterable<T> {
244
- const resolved: unknown = isFunction(value) ? (value as () => unknown)() : value;
245
-
246
- const variable = (resolved as Record<symbol, unknown> | undefined)?.[cssVarSymbol];
247
- if (!isUndefined(variable)) {
248
- yield variable as T;
249
- return;
250
- }
251
- if (typeof resolved === "object" && resolved !== null && Symbol.iterator in resolved) {
252
- yield* resolved as Iterable<T>;
253
- return;
254
- }
255
- yield resolved as T;
256
- }
257
-
258
- function* flattenTokens(
259
- token: Token,
260
- value: Tokens,
261
- parents: string[],
262
- ): Generator<[string, unknown]> {
263
- for (const [property, child] of Object.entries(value)) {
264
- if (property === SELF) continue;
265
- if (isPlainObject(child)) {
266
- yield* flattenTokens(token, child, [...parents, property]);
267
- continue;
268
- }
269
- yield [token.cssVar([...parents, property]), child];
270
- }
271
- }
272
-
273
- function kebabCase(value: string): string {
274
- return value.replace(/([A-Z])/g, "-$1").toLowerCase();
275
- }
@@ -1,37 +0,0 @@
1
- export function isUndefined(value: unknown): value is undefined {
2
- return value === undefined;
3
- }
4
-
5
- export function isNull(value: unknown): value is null {
6
- return value === null;
7
- }
8
-
9
- export function isString(value: unknown): value is string {
10
- return typeof value === "string";
11
- }
12
-
13
- export function isFunction(value: unknown): value is (...args: never[]) => unknown {
14
- return typeof value === "function";
15
- }
16
-
17
- export function isPlainObject(value: unknown): value is Record<string, unknown> {
18
- return typeof value === "object" && value !== null && !Array.isArray(value);
19
- }
20
-
21
- export function toMerged<T>(target: T, source: unknown): T {
22
- if (!isPlainObject(target) || !isPlainObject(source)) return source as T;
23
- const result: Record<string, unknown> = { ...target };
24
- for (const [key, value] of Object.entries(source)) {
25
- result[key] = key in result ? toMerged(result[key], value) : value;
26
- }
27
- return result as T;
28
- }
29
-
30
- export function mapKeys<T, K extends string>(
31
- source: Record<string, T>,
32
- map: (key: string, value: T) => K,
33
- ): Record<K, T> {
34
- const result = {} as Record<K, T>;
35
- for (const [key, value] of Object.entries(source)) result[map(key, value)] = value;
36
- return result;
37
- }