@gramlot/gramlot 0.2.20 → 0.3.1
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/dist/gramlot.js +1343 -303
- package/dist/gramlot.min.js +363 -24
- package/package.json +6 -3
- package/src/binding/ask-dialog.js +2 -2
- package/src/binding/inline.js +3 -10
- package/src/binding/installation.js +2 -1
- package/src/binding/pointer.js +12 -148
- package/src/binding/providers.js +2 -1
- package/src/binding/runtime.js +2 -1
- package/src/bootstrap.d.ts +2 -0
- package/src/bootstrap.js +9 -2
- package/src/builder/gramlot-builder.js +21 -4
- package/src/builder/source.js +11 -10
- package/src/components/bases.js +182 -0
- package/src/components/buttons.js +254 -0
- package/src/components/choice-editor.js +221 -0
- package/src/components/choices.js +13 -0
- package/src/components/date-calendar.js +139 -0
- package/src/components/field-state.js +166 -0
- package/src/components/formlet-labels.js +80 -0
- package/src/components/index.js +5 -0
- package/src/components/inputs.js +196 -0
- package/src/components/labelbox.js +74 -0
- package/src/components/layout.js +190 -0
- package/src/components/parameters.js +6 -0
- package/src/components/popup.js +22 -0
- package/src/components/registry.js +83 -0
- package/src/components/typed-editor.js +260 -0
- package/src/components/validation.js +138 -0
- package/src/format.js +13 -6
- package/src/gramlot.d.ts +5 -1
- package/src/gramlot.js +8 -1
- package/src/handlers/dom-handler.d.ts +1 -0
- package/src/handlers/dom-handler.js +7 -0
- package/src/index-page-runtime.js +78 -30
- package/src/index-page-styles.js +2 -2
- package/src/index-theme.js +1 -1
- package/src/renderer/attributes.js +3 -40
- package/src/renderer/gramlot-html-renderer.js +4 -3
- package/src/renderer/gramlot-renderer.js +62 -4
- package/src/server/gramlot-server.d.ts +3 -0
- package/src/server/gramlot-server.js +10 -3
- package/src/server/index-page.d.ts +1 -0
- package/src/server/index-page.js +8 -3
- package/src/server/page-base.js +1 -0
- package/src/server/page.d.ts +1 -0
- package/src/server/resources.d.ts +2 -0
- package/src/view/button.js +17 -13
- package/src/view/controls.js +152 -4
- package/src/view/html.js +18 -0
- package/themes/gramlot-base/README.md +6 -0
- package/themes/gramlot-base/theme.css +34 -6
- package/themes/gramlot-compact/README.md +6 -0
- package/themes/gramlot-compact/theme.css +8 -4
- package/themes/joanna/README.md +23 -0
- package/themes/joanna/theme.css +89 -0
- package/themes/mimi/README.md +23 -0
- package/themes/mimi/theme.css +89 -0
- package/tools/gramlot-tools-inspector.js +56 -23
- package/tools/inspector-agent.js +8 -4
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {Bag} from '@genrojs/bag';
|
|
2
|
+
import {pointerTemplate} from '@genrojs/builders';
|
|
3
|
+
|
|
4
|
+
/** Shared ordered rules. Context supplies activated callbacks/RPC; this module never writes Data. */
|
|
5
|
+
export const validationRules = ['select', 'notnull', 'empty', 'case', 'len', 'min', 'max', 'email', 'regex', 'call', 'remote'];
|
|
6
|
+
const deferredRules = ['nodup', 'exist', 'gridnodup'];
|
|
7
|
+
const empty = value => value == null || value === '';
|
|
8
|
+
const then = (value, next) => value instanceof Promise ? value.then(next) : next(value);
|
|
9
|
+
|
|
10
|
+
export function validateInput(value, parameters, context = {}) {
|
|
11
|
+
const result = {value, modified:false, error:null, warnings:[], issues:[], datachanges:[]};
|
|
12
|
+
const validations = Object.fromEntries(Object.entries(parameters).map(([key, val]) => [key.slice(9), val]));
|
|
13
|
+
const configured = name => Object.hasOwn(parameters, `validate_${name}`) && parameters[`validate_${name}`] != null;
|
|
14
|
+
for (const name of deferredRules) if (configured(name)) throw new Error(`validate_${name} requires the DB/grid integration.`);
|
|
15
|
+
const invoke = (name, current, expression = false) => context.invoke(name, parameters[name], {
|
|
16
|
+
...validations, value:current, result, validations, userChange:true, signal:context.signal
|
|
17
|
+
}, expression);
|
|
18
|
+
const consume = (rule, output) => {
|
|
19
|
+
if (output == null || output === true) return;
|
|
20
|
+
if (typeof output !== 'boolean' && typeof output !== 'string' && (typeof output !== 'object' || Array.isArray(output))) throw new TypeError('A validator returns true, false, null, an error code, or a result object/Bag.');
|
|
21
|
+
const prefix = `validate_${rule}`;
|
|
22
|
+
const response = output instanceof Bag ? Object.fromEntries(output.getNodes().map(node => [node.label, node.value])) : typeof output === 'object' ? output : {errorcode:output === false ? 'error' : output};
|
|
23
|
+
if (Object.hasOwn(response, 'value')) {
|
|
24
|
+
result.modified ||= !Object.is(result.value, response.value);
|
|
25
|
+
result.value = response.value;
|
|
26
|
+
}
|
|
27
|
+
if (response.data != null) { context.checkDataPatch(response.data); result.datachanges.push(response.data); }
|
|
28
|
+
if (!response.errorcode) return;
|
|
29
|
+
const warning = parameters[`${prefix}_iswarning`] ?? response.iswarning
|
|
30
|
+
?? Boolean(parameters[`${prefix}_warning`] && !parameters[`${prefix}_error`]);
|
|
31
|
+
const message = parameters[`${prefix}_${response.errorcode}`]
|
|
32
|
+
|| parameters[`${prefix}_${warning ? 'warning' : 'error'}`]
|
|
33
|
+
|| response.message || parameters[`${prefix}_${warning ? 'error' : 'warning'}`] || String(response.errorcode);
|
|
34
|
+
const renderedMessage = pointerTemplate(message, name => name ? ({...validations, ...response, value:result.value})[name] : result.value);
|
|
35
|
+
if (renderedMessage == null) throw new Error('A validation message references a missing value.');
|
|
36
|
+
const issue = {rule, code:response.errorcode, severity:warning ? 'warning' : 'error', message:renderedMessage};
|
|
37
|
+
result.issues.push(issue);
|
|
38
|
+
if (warning) result.warnings.push(renderedMessage);
|
|
39
|
+
else { result.error = renderedMessage; result.required = Boolean(response.required); }
|
|
40
|
+
};
|
|
41
|
+
const step = index => {
|
|
42
|
+
if (context.signal?.aborted) throw context.signal.reason;
|
|
43
|
+
if (result.error || index === validationRules.length) return result;
|
|
44
|
+
const rule = validationRules[index], prefix = `validate_${rule}`, param = parameters[prefix];
|
|
45
|
+
if (!configured(rule) || (param === false && rule !== 'empty')) return step(index + 1);
|
|
46
|
+
const run = allowed => {
|
|
47
|
+
if (!allowed) return step(index + 1);
|
|
48
|
+
let output;
|
|
49
|
+
if (rule === 'remote' && result.value == null) return step(index + 1);
|
|
50
|
+
if (rule === 'call') output = invoke(prefix, result.value);
|
|
51
|
+
else if (rule === 'remote') output = context.remote(param, {...remoteArguments(parameters), value:result.value}, context.signal);
|
|
52
|
+
else output = localRule(rule, param, result.value, context);
|
|
53
|
+
return then(output, answer => {
|
|
54
|
+
if (context.signal?.aborted) throw context.signal.reason;
|
|
55
|
+
const complete = () => { consume(rule, answer); return step(index + 1); };
|
|
56
|
+
if (rule === 'remote' && parameters.validate__onResult) return then(context.invoke('validate__onResult', parameters.validate__onResult,
|
|
57
|
+
{result:answer, value:result.value, validations, signal:context.signal}), complete);
|
|
58
|
+
return complete();
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const condition = parameters[`${prefix}_if`];
|
|
62
|
+
return then(condition == null ? true : typeof condition === 'boolean' ? condition
|
|
63
|
+
: invoke(`${prefix}_if`, result.value, true), run);
|
|
64
|
+
};
|
|
65
|
+
return step(0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function remoteArguments(parameters) {
|
|
69
|
+
const excluded = new Set(['if', 'error', 'warning', 'iswarning']);
|
|
70
|
+
return Object.fromEntries(Object.entries(parameters).filter(([key]) => key.startsWith('validate_remote_')
|
|
71
|
+
&& !excluded.has(key.slice(16))).map(([key, value]) => [key.slice(16), value]));
|
|
72
|
+
}
|
|
73
|
+
function fail(errorcode, message, extra = {}) { return {errorcode, message, ...extra}; }
|
|
74
|
+
function localRule(rule, param, value, context) {
|
|
75
|
+
if (rule === 'select') return context.selection(value);
|
|
76
|
+
if (rule === 'notnull') return empty(value) && param ? fail('notnull', 'A value is required.', {required:true}) : null;
|
|
77
|
+
if (rule === 'empty') return empty(value) ? {value:param} : null;
|
|
78
|
+
if (rule === 'len') {
|
|
79
|
+
if (typeof param !== 'string' || !/^(?:\d+|\d+:\d*|:\d+)$/.test(param)) throw new Error('Invalid validate_len: use a length or min:max.');
|
|
80
|
+
const [low, high] = param.split(':');
|
|
81
|
+
const min = Number(low || 0), max = high === undefined ? min : high === '' ? Infinity : Number(high);
|
|
82
|
+
if (min > max) throw new Error('Invalid validate_len: minimum exceeds maximum.');
|
|
83
|
+
if (empty(value)) return;
|
|
84
|
+
if (typeof value !== 'string') throw new TypeError('validate_len requires a text value.');
|
|
85
|
+
if (value.length < min || value.length > max) return fail(min === max ? 'wrong length' : value.length < min ? 'too short' : 'too long',
|
|
86
|
+
min === max ? `Enter exactly ${min} characters.` : max === Infinity ? `Enter at least ${min} characters.`
|
|
87
|
+
: min === 0 ? `Enter no more than ${max} characters.` : `Enter between ${min} and ${max} characters.`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (empty(value)) return;
|
|
91
|
+
if (rule === 'case') {
|
|
92
|
+
if (typeof value !== 'string') throw new TypeError('validate_case requires a text value.');
|
|
93
|
+
switch (param) {
|
|
94
|
+
case 'upper': case 'u': return {value:value.toUpperCase()};
|
|
95
|
+
case 'lower': case 'l': return {value:value.toLowerCase()};
|
|
96
|
+
case 'title': case 't': return {value:value.replace(/\p{L}[\p{L}\p{M}]*/gu, word => word[0].toUpperCase() + word.slice(1).toLowerCase())};
|
|
97
|
+
case 'capitalize': case 'c': return {value:value[0].toUpperCase() + value.slice(1).toLowerCase()};
|
|
98
|
+
default: throw new Error('Invalid validate_case: use upper, lower, title or capitalize.');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (rule === 'min' || rule === 'max') {
|
|
102
|
+
let comparison;
|
|
103
|
+
if (context.isDecimal?.(value)) comparison = value.comparedTo(param);
|
|
104
|
+
else if (value instanceof Date && param instanceof Date) comparison = value.getTime() - param.getTime();
|
|
105
|
+
else if (typeof value === 'number' && Number.isFinite(value) && typeof param === 'number' && Number.isFinite(param)) comparison = value - param;
|
|
106
|
+
else throw new TypeError(`validate_${rule} requires matching numeric or date/time values.`);
|
|
107
|
+
if (rule === 'min' ? comparison < 0 : comparison > 0) return fail(rule, `Value must be ${rule === 'min' ? 'at least' : 'at most'} ${param}.`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (rule === 'email') {
|
|
111
|
+
if (typeof value !== 'string') throw new TypeError('validate_email requires a text value.');
|
|
112
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/u.test(value) ? null : fail('email', 'Check email format.', {iswarning:true});
|
|
113
|
+
}
|
|
114
|
+
if (rule === 'regex') {
|
|
115
|
+
if (typeof value !== 'string' || typeof param !== 'string') throw new TypeError('validate_regex requires text.');
|
|
116
|
+
const pattern = param.trim(), negative = pattern.startsWith('!');
|
|
117
|
+
return new RegExp(negative ? pattern.slice(1) : pattern, 'u').test(value) !== negative ? null : fail('regex', 'The value does not match the required pattern.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Shared metadata exports the same rule types to both Builders. */
|
|
122
|
+
const text = {dtype:'T', nullable:true, binding:'read'};
|
|
123
|
+
const boolean = {dtype:'B', nullable:true, binding:'read'};
|
|
124
|
+
const scalar = {dtype:['T','L','N','R','B','D','H','DH','DHZ'], nullable:true, binding:'read'};
|
|
125
|
+
export const validationParameters = {
|
|
126
|
+
validate_select:boolean, validate_notnull:{...boolean,default:false}, validate_empty:scalar,
|
|
127
|
+
validate_case:{...text,enum:['upper','lower','title','capitalize','u','l','t','c']},
|
|
128
|
+
validate_len:text, validate_min:scalar, validate_max:scalar, validate_email:boolean,
|
|
129
|
+
validate_regex:text, validate_call:{dtype:'T',nullable:true}, validate_remote:text,
|
|
130
|
+
validate_onAccept:{dtype:'T',nullable:true}, validate_onReject:{dtype:'T',nullable:true},
|
|
131
|
+
validate__onResult:{dtype:'T',nullable:true},
|
|
132
|
+
validate_timeout:{dtype:'L',nullable:true,binding:'read'},
|
|
133
|
+
...Object.fromEntries(validationRules.flatMap(rule => [
|
|
134
|
+
[`validate_${rule}_if`, {dtype:['T','B'],nullable:true}],
|
|
135
|
+
[`validate_${rule}_iswarning`, boolean],
|
|
136
|
+
...['error','warning'].map(suffix => [`validate_${rule}_${suffix}`, {...text,qualification:'intl_str'}])
|
|
137
|
+
]))
|
|
138
|
+
};
|
package/src/format.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {isDecimal} from '@genrojs/tytx';
|
|
1
2
|
/** Bounded numeric patterns and temporal styles for Gramlot's formatting contract. */
|
|
2
3
|
|
|
3
4
|
export function validateMask(mask) {
|
|
@@ -22,8 +23,9 @@ function inferredType(value) {
|
|
|
22
23
|
if (midnight && !epochDay) return 'D';
|
|
23
24
|
return 'DHZ';
|
|
24
25
|
}
|
|
26
|
+
if (isDecimal(value)) return 'N';
|
|
25
27
|
if (typeof value === 'number') return Number.isInteger(value) ? 'L' : 'R';
|
|
26
|
-
throw new TypeError('Formatting requires finite JavaScript numbers or valid Date objects');
|
|
28
|
+
throw new TypeError('Formatting requires finite JavaScript numbers, TYTX Decimal values or valid Date objects');
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
function temporalText(value, dtype, {pattern = 'short', locale, timeZone}) {
|
|
@@ -88,8 +90,8 @@ export function formatValue(value, options = {}, context = {}) {
|
|
|
88
90
|
if (!temporal && !['L', 'R', 'N'].includes(dtype)) throw new RangeError(`Unsupported format dtype: ${dtype}`);
|
|
89
91
|
if (temporal) {
|
|
90
92
|
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw new TypeError(`${dtype} requires a valid Date object`);
|
|
91
|
-
} else if (typeof value
|
|
92
|
-
throw new TypeError(`${dtype} formatting requires finite JavaScript numbers`);
|
|
93
|
+
} else if (!(typeof value === 'number' && Number.isFinite(value)) && !(isDecimal(value) && !['NaN', 'Infinity', '-Infinity'].includes(value.toString()))) {
|
|
94
|
+
throw new TypeError(`${dtype} formatting requires finite JavaScript numbers or TYTX Decimal values`);
|
|
93
95
|
}
|
|
94
96
|
if (dtype === 'L' && !Number.isInteger(value)) throw new TypeError('L formatting requires an integer');
|
|
95
97
|
const {pattern, locale, mask} = options;
|
|
@@ -104,8 +106,12 @@ export function formatValue(value, options = {}, context = {}) {
|
|
|
104
106
|
return applyMask(text, mask);
|
|
105
107
|
}
|
|
106
108
|
const {positive, zero, negative} = numericPattern(pattern);
|
|
109
|
+
const decimal = isDecimal(value);
|
|
110
|
+
const zeroValue = decimal ? value.eq(0) : value === 0;
|
|
111
|
+
const negativeValue = decimal ? value.lt(0) : value < 0;
|
|
112
|
+
if (decimal && new Intl.NumberFormat('en', {useGrouping: false}).format('9007199254740993') !== '9007199254740993') throw new Error('This browser cannot format Decimal without precision loss');
|
|
107
113
|
let text;
|
|
108
|
-
if (
|
|
114
|
+
if (zeroValue && zero !== null) {
|
|
109
115
|
if (zero === '') return '';
|
|
110
116
|
if (zero === '-') text = '-';
|
|
111
117
|
else {
|
|
@@ -113,8 +119,9 @@ export function formatValue(value, options = {}, context = {}) {
|
|
|
113
119
|
text = section.prefix + new Intl.NumberFormat(locale, section.intl).format(0) + section.suffix;
|
|
114
120
|
}
|
|
115
121
|
} else {
|
|
116
|
-
const affix =
|
|
117
|
-
const number =
|
|
122
|
+
const affix = negativeValue && negative ? negative : positive;
|
|
123
|
+
const number = decimal ? (negativeValue && negative ? value.abs() : value).toString()
|
|
124
|
+
: negativeValue && negative ? -value : (value === 0 ? 0 : value);
|
|
118
125
|
text = affix.prefix + new Intl.NumberFormat(locale, positive.intl).format(number) + affix.suffix;
|
|
119
126
|
}
|
|
120
127
|
return applyMask(text, mask);
|
package/src/gramlot.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type {DomElement, DomDocument, DomEvent, DomWindow} from './dom.d.ts';
|
|
7
7
|
import type {Bag} from '@genrojs/bag';
|
|
8
|
+
import type {createDecimal} from '@genrojs/tytx';
|
|
8
9
|
import type {SourceBagNode} from '@genrojs/builders';
|
|
9
10
|
import type {RpcTransport} from './handlers/rpc-handler.js';
|
|
10
11
|
import type {SourceHandler} from './handlers/source-handler.js';
|
|
@@ -16,6 +17,8 @@ import type {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
|
16
17
|
export interface GramlotOptions {
|
|
17
18
|
/** Formatting locale of this page; null/omitted uses the browser locale. */
|
|
18
19
|
locale?: string | null;
|
|
20
|
+
/** Declared device suitability; empty means unspecified. */
|
|
21
|
+
devices?: Array<'desktop' | 'tablet' | 'phone'>;
|
|
19
22
|
/** Timezone for instants; null/omitted uses the browser timezone. */
|
|
20
23
|
timeZone?: string | null;
|
|
21
24
|
/** The id of the server page, as registered by the server. */
|
|
@@ -63,6 +66,7 @@ export type Publication = string | {topic: string; nodeId: string} |
|
|
|
63
66
|
|
|
64
67
|
/** One Gramlot page: lifecycle, Data and the four proxies `src`, `rpc`, `dom`, `utl`. */
|
|
65
68
|
export class Gramlot {
|
|
69
|
+
readonly devices: readonly ('desktop' | 'tablet' | 'phone')[];
|
|
66
70
|
locale: string;
|
|
67
71
|
timeZone: string;
|
|
68
72
|
/** The id of the server page. */
|
|
@@ -100,7 +104,7 @@ export class Gramlot {
|
|
|
100
104
|
/** Remove a registration; repeating removal of an owned handle is harmless. */
|
|
101
105
|
unsubscribe(registration: SubscriptionHandle): void;
|
|
102
106
|
/** Format a number, Date or null. Explicit dtype overrides TYTX-style Date inference. */
|
|
103
|
-
format(value: number | Date | null, options?: string | FormatOptions): string;
|
|
107
|
+
format(value: number | Date | ReturnType<typeof createDecimal> | null, options?: string | FormatOptions): string;
|
|
104
108
|
/** Load `main` from the server and mount it; resolves with the instance. */
|
|
105
109
|
start(): Promise<Gramlot>;
|
|
106
110
|
/** Request `main` from the transport and mount it. */
|
package/src/gramlot.js
CHANGED
|
@@ -10,6 +10,8 @@ import {RpcHandler} from './handlers/rpc-handler.js';
|
|
|
10
10
|
import {DomHandler} from './handlers/dom-handler.js';
|
|
11
11
|
import {SubscriptionsHandler} from './handlers/subscriptions-handler.js';
|
|
12
12
|
import {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
13
|
+
import buttons from './components/buttons.js';
|
|
14
|
+
import {ComponentCollection} from './components/registry.js';
|
|
13
15
|
import {formatValue} from './format.js';
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -19,10 +21,15 @@ import {formatValue} from './format.js';
|
|
|
19
21
|
export class Gramlot {
|
|
20
22
|
constructor({pageId, rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close', rootId = 'gramlot-root', capabilities = [],
|
|
21
23
|
element = null, document = element?.ownerDocument ?? globalThis.document, transport = null, collections = [],
|
|
22
|
-
locale = null, timeZone = null} = {}) {
|
|
24
|
+
locale = null, timeZone = null, devices = []} = {}) {
|
|
25
|
+
buttons.register(document.defaultView);
|
|
26
|
+
for (const collection of collections) {
|
|
27
|
+
if (collection instanceof ComponentCollection) collection.register(document.defaultView);
|
|
28
|
+
}
|
|
23
29
|
this.pageId = pageId;
|
|
24
30
|
const browserContext = locale == null || timeZone == null
|
|
25
31
|
? document.defaultView.Intl.DateTimeFormat().resolvedOptions() : null;
|
|
32
|
+
this.devices = Object.freeze([...devices]);
|
|
26
33
|
this.locale = locale ?? browserContext.locale;
|
|
27
34
|
this.timeZone = timeZone ?? browserContext.timeZone;
|
|
28
35
|
Object.defineProperty(this, '_subscriptions', {value: new SubscriptionsHandler(this)});
|
|
@@ -10,6 +10,7 @@ import {Handler} from './handler.js';
|
|
|
10
10
|
|
|
11
11
|
/** The DOM and its correspondence with the Source. */
|
|
12
12
|
export class DomHandler extends Handler {
|
|
13
|
+
setTouchMode(mode?: 'auto' | 'on' | 'off'): void;
|
|
13
14
|
/** Resolve a node or DOM reference descriptor. */
|
|
14
15
|
reference(descriptor: SourceReference): SourceBagNode | DomElement;
|
|
15
16
|
/** The Source node of the nearest element generated by the renderer. */
|
|
@@ -8,6 +8,13 @@ import {Handler} from './handler.js';
|
|
|
8
8
|
|
|
9
9
|
/** The DOM and its correspondence with the Source. */
|
|
10
10
|
export class DomHandler extends Handler {
|
|
11
|
+
/** Size controls for the input device without rebuilding the page. */
|
|
12
|
+
setTouchMode(mode = 'auto') {
|
|
13
|
+
if (!['auto', 'on', 'off'].includes(mode)) throw new TypeError(`Invalid touch mode: ${mode}`);
|
|
14
|
+
const root = this.gramlot.src.renderer.destination.ownerDocument.documentElement;
|
|
15
|
+
if (mode === 'auto') root.removeAttribute('data-gramlot-touch');
|
|
16
|
+
else root.setAttribute('data-gramlot-touch', mode);
|
|
17
|
+
}
|
|
11
18
|
reference(descriptor) { return this.gramlot.src.renderer.references.resolve(descriptor); }
|
|
12
19
|
/** The Source node of the nearest element generated by the renderer (§4.11bis). */
|
|
13
20
|
getBaseSourceNode(domNode) { return this.gramlot.src.renderer.getBaseSourceNode(domNode); }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @ts-self-types="./index-page-runtime.d.ts" */
|
|
2
|
-
import {
|
|
2
|
+
import {appearanceStyles} from './index-page-styles.js';
|
|
3
3
|
import {THEME_READY, THEME_SET, THEMES, APPEARANCES} from './index-theme.js';
|
|
4
4
|
|
|
5
5
|
/** Index-page behavior; writes UI state through the existing Source records. */
|
|
@@ -15,6 +15,10 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
15
15
|
const appearance = byId('index-appearance');
|
|
16
16
|
const sidebar = byId('index-sidebar');
|
|
17
17
|
const sidebarHandle = byId('index-sidebar-divider');
|
|
18
|
+
const navigationToggle = byId('index-navigation-toggle');
|
|
19
|
+
const codeToggle = byId('index-code-toggle');
|
|
20
|
+
const codeSidebar = byId('index-code');
|
|
21
|
+
const codeHandle = byId('index-code-divider');
|
|
18
22
|
// localStorage is scoped to this origin; the path separates mounted galleries.
|
|
19
23
|
const preferencesKey = `gramlot.${shell.id}.preferences:${window.location.pathname}`;
|
|
20
24
|
let preferences = {};
|
|
@@ -39,11 +43,16 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
39
43
|
state.setItem('keyboard', (keyboard?.checked ?? false));
|
|
40
44
|
state.setItem('theme', (theme?.value ?? 'light'));
|
|
41
45
|
state.setItem('appearance', (appearance?.value ?? 'compact'));
|
|
46
|
+
state.setItem('navigationVisible', preferences.navigationVisible !== false);
|
|
47
|
+
state.setItem('codeVisible', preferences.codeVisible !== false);
|
|
42
48
|
const savePreferences = () => {
|
|
43
49
|
try {
|
|
44
50
|
window.localStorage.setItem(preferencesKey, JSON.stringify({
|
|
45
51
|
theme: state.getItem('theme'), appearance: state.getItem('appearance'),
|
|
46
52
|
sidebarWidth: state.getItem('preferredSidebarWidth'),
|
|
53
|
+
codeWidth: state.getItem('preferredCodeWidth'),
|
|
54
|
+
navigationVisible: state.getItem('navigationVisible'),
|
|
55
|
+
codeVisible: state.getItem('codeVisible'),
|
|
47
56
|
}));
|
|
48
57
|
} catch (error) {
|
|
49
58
|
// A browser may deny storage (including opaque file origins) or exhaust its quota.
|
|
@@ -53,7 +62,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
53
62
|
};
|
|
54
63
|
const entries = new Map();
|
|
55
64
|
const releases = [];
|
|
56
|
-
const style = root.builder.wrapSource(root.value).style(
|
|
65
|
+
const style = root.builder.wrapSource(root.value).style(appearanceStyles[appearance?.value ?? 'compact']);
|
|
57
66
|
let drag = null;
|
|
58
67
|
let disposed = false;
|
|
59
68
|
let installPrompt = null;
|
|
@@ -83,10 +92,27 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
83
92
|
const send = frame => frame.contentWindow.postMessage({type: THEME_SET, theme: state.getItem('theme'), appearance: state.getItem('appearance')}, '*');
|
|
84
93
|
const applyTheme = () => {
|
|
85
94
|
document.documentElement.setAttribute('data-theme', state.getItem('theme'));
|
|
86
|
-
style.
|
|
95
|
+
style.setValue(appearanceStyles[state.getItem('appearance')]);
|
|
87
96
|
for (const {frame} of entries.values()) if (frame) send(frame);
|
|
88
97
|
};
|
|
89
98
|
const updateInspector = () => onSelection(entries, state.getItem('active'));
|
|
99
|
+
const updatePanels = () => {
|
|
100
|
+
if (navigationToggle) {
|
|
101
|
+
const visible = state.getItem('navigationVisible');
|
|
102
|
+
set(sidebar, {hidden: !visible});
|
|
103
|
+
set(sidebarHandle, {hidden: !visible});
|
|
104
|
+
set(navigationToggle, {aria_expanded: String(visible)});
|
|
105
|
+
set(shell, {data_navigation_hidden: String(!visible)});
|
|
106
|
+
}
|
|
107
|
+
if (codeSidebar) {
|
|
108
|
+
const available = Boolean(entries.get(state.getItem('active'))?.code);
|
|
109
|
+
const visible = available && state.getItem('codeVisible');
|
|
110
|
+
set(codeSidebar, {hidden: !visible});
|
|
111
|
+
set(codeHandle, {hidden: !visible});
|
|
112
|
+
set(codeToggle, {disabled: !available, aria_expanded: String(visible)});
|
|
113
|
+
set(shell, {data_code_visible: String(visible)});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
90
116
|
function select(key) {
|
|
91
117
|
const entry = entries.get(key);
|
|
92
118
|
if (!opened.getItem(key)) {
|
|
@@ -99,29 +125,38 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
99
125
|
const active = current === key;
|
|
100
126
|
set(item.tab, {aria_selected: String(active), tabindex: active && state.getItem('keyboard') ? 0 : -1});
|
|
101
127
|
set(item.panel, {hidden: !active});
|
|
128
|
+
if (item.code) set(item.code, {hidden: !active});
|
|
102
129
|
if (item.open) set(item.open, {aria_current: active ? 'page' : null});
|
|
103
130
|
}
|
|
104
131
|
state.setItem('active', key);
|
|
132
|
+
updatePanels();
|
|
105
133
|
updateInspector();
|
|
106
134
|
}
|
|
107
|
-
function setRatio(entry, value) {
|
|
108
|
-
const ratio = Math.max(20, Math.min(80, value));
|
|
109
|
-
state.setItem(`ratio.${entry.key}`, ratio);
|
|
110
|
-
set(entry.split, {style: `--split-position: ${ratio}%`});
|
|
111
|
-
set(entry.handle, {aria_valuenow: ratio});
|
|
112
|
-
}
|
|
113
135
|
const sidebarMaximum = () => Math.max(120, Math.min(460, Math.floor(window.innerWidth * .6)));
|
|
136
|
+
const applyWidths = () => set(shell, {style: `--sidebar-width: ${state.getItem('sidebarWidth')}px; --code-width: ${state.getItem('codeWidth') ?? 420}px`});
|
|
114
137
|
const setSidebarWidth = (value, remember = false) => {
|
|
115
138
|
const maximum = sidebarMaximum();
|
|
116
139
|
const width = Math.max(120, Math.min(maximum, value));
|
|
117
140
|
state.setItem('sidebarWidth', width);
|
|
118
|
-
|
|
141
|
+
applyWidths();
|
|
119
142
|
set(sidebarHandle, {aria_valuenow: width, aria_valuemax: maximum});
|
|
120
143
|
if (remember) {
|
|
121
144
|
state.setItem('preferredSidebarWidth', width);
|
|
122
145
|
savePreferences();
|
|
123
146
|
}
|
|
124
147
|
};
|
|
148
|
+
const codeMaximum = () => Math.max(200, Math.floor(window.innerWidth * .6));
|
|
149
|
+
const setCodeWidth = (value, remember = false) => {
|
|
150
|
+
const maximum = codeMaximum();
|
|
151
|
+
const width = Math.max(200, Math.min(maximum, value));
|
|
152
|
+
state.setItem('codeWidth', width);
|
|
153
|
+
applyWidths();
|
|
154
|
+
set(codeHandle, {aria_valuenow: width, aria_valuemax: maximum});
|
|
155
|
+
if (remember) {
|
|
156
|
+
state.setItem('preferredCodeWidth', width);
|
|
157
|
+
savePreferences();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
125
160
|
const beginDrag = (handle, event, move) => {
|
|
126
161
|
if (event.button !== 0) return;
|
|
127
162
|
stopDrag();
|
|
@@ -167,6 +202,36 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
167
202
|
? savedWidth : sidebar.getBoundingClientRect().width || Number(sidebarHandle.getAttribute('aria-valuenow'));
|
|
168
203
|
state.setItem('preferredSidebarWidth', width);
|
|
169
204
|
setSidebarWidth(width);
|
|
205
|
+
listen(navigationToggle, 'click', () => {
|
|
206
|
+
state.setItem('navigationVisible', !state.getItem('navigationVisible'));
|
|
207
|
+
updatePanels();
|
|
208
|
+
savePreferences();
|
|
209
|
+
});
|
|
210
|
+
listen(codeToggle, 'click', () => {
|
|
211
|
+
state.setItem('codeVisible', !state.getItem('codeVisible'));
|
|
212
|
+
updatePanels();
|
|
213
|
+
savePreferences();
|
|
214
|
+
});
|
|
215
|
+
if (codeHandle) {
|
|
216
|
+
const saved = preferences.codeWidth;
|
|
217
|
+
const width = typeof saved === 'number' && Number.isFinite(saved) && saved >= 200 ? saved : 420;
|
|
218
|
+
state.setItem('preferredCodeWidth', width);
|
|
219
|
+
setCodeWidth(width);
|
|
220
|
+
listen(codeHandle, 'keydown', event => {
|
|
221
|
+
const current = state.getItem('codeWidth');
|
|
222
|
+
const value = event.key === 'ArrowLeft' ? current + 10 : event.key === 'ArrowRight' ? current - 10
|
|
223
|
+
: event.key === 'Home' ? 200 : event.key === 'End' ? codeMaximum() : null;
|
|
224
|
+
if (value == null) return;
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
setCodeWidth(value, true);
|
|
227
|
+
});
|
|
228
|
+
listen(codeHandle, 'pointerdown', event => beginDrag(codeHandle, event,
|
|
229
|
+
x => setCodeWidth(Math.round(shell.getBoundingClientRect().right - x), true)));
|
|
230
|
+
listen(codeHandle, 'lostpointercapture', () => {
|
|
231
|
+
if (drag?.handle === codeHandle) stopDrag();
|
|
232
|
+
});
|
|
233
|
+
listen(window, 'resize', () => setCodeWidth(state.getItem('preferredCodeWidth')));
|
|
234
|
+
}
|
|
170
235
|
listen(sidebarHandle, 'keydown', event => {
|
|
171
236
|
const current = state.getItem('sidebarWidth');
|
|
172
237
|
const value = event.key === 'ArrowLeft' ? current - 10 : event.key === 'ArrowRight' ? current + 10
|
|
@@ -184,6 +249,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
184
249
|
for (const tab of shell.querySelectorAll('.index-tabs button')) {
|
|
185
250
|
const key = tab.id.slice('tab-'.length);
|
|
186
251
|
const entry = {key, tab, panel: byId(`panel-${key}`),
|
|
252
|
+
code: byId(`codepane-${key}`),
|
|
187
253
|
open: key === 'intro' ? null : byId(`open-${key}`)};
|
|
188
254
|
entries.set(key, entry);
|
|
189
255
|
if (!tab.hidden) opened.setItem(key, true);
|
|
@@ -205,26 +271,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
205
271
|
prepareEntry(entry, {byId, node, set, listen});
|
|
206
272
|
if (entry.panel.classList.contains('index-category')) continue;
|
|
207
273
|
entry.frame = byId(`frame-${key}`);
|
|
208
|
-
entry.split = byId(`split-${key}`);
|
|
209
|
-
entry.handle = byId(`divider-${key}`);
|
|
210
|
-
if (entry.handle) state.setItem(`ratio.${key}`, Number(entry.handle.getAttribute('aria-valuenow')));
|
|
211
274
|
listen(entry.frame, 'load', () => send(entry.frame));
|
|
212
|
-
if (!entry.handle) continue;
|
|
213
|
-
listen(entry.handle, 'keydown', event => {
|
|
214
|
-
const current = state.getItem(`ratio.${key}`);
|
|
215
|
-
const value = event.key === 'ArrowLeft' ? current - 5 : event.key === 'ArrowRight' ? current + 5
|
|
216
|
-
: event.key === 'Home' ? 20 : event.key === 'End' ? 80 : null;
|
|
217
|
-
if (value == null) return;
|
|
218
|
-
event.preventDefault();
|
|
219
|
-
setRatio(entry, value);
|
|
220
|
-
});
|
|
221
|
-
listen(entry.handle, 'pointerdown', event => beginDrag(entry.handle, event, x => {
|
|
222
|
-
const bounds = entry.split.getBoundingClientRect();
|
|
223
|
-
if (bounds.width > 0) setRatio(entry, Math.round((x - bounds.left) * 100 / bounds.width));
|
|
224
|
-
}));
|
|
225
|
-
listen(entry.handle, 'lostpointercapture', () => {
|
|
226
|
-
if (drag?.handle === entry.handle) stopDrag();
|
|
227
|
-
});
|
|
228
275
|
}
|
|
229
276
|
listen(document, 'pointermove', event => {
|
|
230
277
|
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
@@ -243,7 +290,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
243
290
|
}
|
|
244
291
|
});
|
|
245
292
|
listen(appearance, 'change', () => {
|
|
246
|
-
if (!APPEARANCES.has((appearance?.value ?? 'compact'))) throw new Error('
|
|
293
|
+
if (!APPEARANCES.has((appearance?.value ?? 'compact'))) throw new Error('Unknown index appearance');
|
|
247
294
|
state.setItem('appearance', (appearance?.value ?? 'compact'));
|
|
248
295
|
set(appearance, {value: (appearance?.value ?? 'compact')});
|
|
249
296
|
for (const option of appearance.options) set(option, {selected: option.value === (appearance?.value ?? 'compact')});
|
|
@@ -265,6 +312,7 @@ export function mountIndexPage(renderer, root, onSelection = () => {}, prepareEn
|
|
|
265
312
|
}
|
|
266
313
|
});
|
|
267
314
|
applyTheme();
|
|
315
|
+
updatePanels();
|
|
268
316
|
updateInspector();
|
|
269
317
|
renderer.onDispose(root, dispose);
|
|
270
318
|
} catch (error) {
|
package/src/index-page-styles.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Generated from themes
|
|
2
|
-
export const compactStyle = "/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type=\"button\"]):not([type=\"submit\"]):not([type=\"reset\"]):not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"range\"]):not([type=\"color\"]):not([type=\"file\"]):not([type=\"hidden\"]), select, textarea) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type=\"color\"]) { min-block-size: 28px; }\n :where(input[type=\"file\"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n";
|
|
1
|
+
// Generated from canonical themes; edit themes/, not this file.
|
|
2
|
+
export const appearanceStyles = {"base":"","compact":"/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type=\"button\"]):not([type=\"submit\"]):not([type=\"reset\"]):not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"range\"]):not([type=\"color\"]):not([type=\"file\"]):not([type=\"hidden\"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type=\"color\"]) { min-block-size: 28px; }\n :where(input[type=\"file\"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n","mimi":"/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type=\"button\"]):not([type=\"submit\"]):not([type=\"reset\"]):not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"range\"]):not([type=\"color\"]):not([type=\"file\"]):not([type=\"hidden\"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type=\"color\"]) { min-block-size: 28px; }\n :where(input[type=\"file\"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy mimi; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-background: #EDEEF0;\n --gramlot-surface: #F5F5F6;\n --gramlot-surface-subtle: #E0E1E3;\n --gramlot-ink: #3C3D40;\n --gramlot-text-secondary: #6B6E72;\n --gramlot-border: #BDBFC2;\n --gramlot-border-control: #9EA0A3;\n --gramlot-navigation: #48494C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #0071E3;\n --gramlot-action-hover: #005BBB;\n --gramlot-brand-blue: #0071E3;\n --gramlot-brand-yellow: #9EA0A3;\n --gramlot-selected: #E8F1FC;\n --gramlot-focus-ring: #0071E3;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #E0E1E3;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 4px;\n --gramlot-radius: 3px;\n --gramlot-radius-lg: 3px;\n --gramlot-field-height: 18px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .9em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, \"Helvetica Neue\", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme=\"light\"]) {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme=\"dark\"] {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 12px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) { min-block-size: 24px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n","joanna":"/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type=\"button\"]):not([type=\"submit\"]):not([type=\"reset\"]):not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"range\"]):not([type=\"color\"]):not([type=\"file\"]):not([type=\"hidden\"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type=\"color\"]) { min-block-size: 28px; }\n :where(input[type=\"file\"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy joanna; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-background: #F2F2F7;\n --gramlot-surface: #FFFFFF;\n --gramlot-surface-subtle: #F2F2F7;\n --gramlot-ink: #3A3A3C;\n --gramlot-text-secondary: #636366;\n --gramlot-border: #D1D1D6;\n --gramlot-border-control: #AEAEB2;\n --gramlot-navigation: #3A3A3C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #007AFF;\n --gramlot-action-hover: #0061CC;\n --gramlot-brand-blue: #007AFF;\n --gramlot-brand-yellow: #AEAEB2;\n --gramlot-selected: #E0EFFF;\n --gramlot-focus-ring: #007AFF;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #F2F2F7;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 6px;\n --gramlot-radius: 6px;\n --gramlot-radius-lg: 6px;\n --gramlot-field-height: 20px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .8em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, \"Helvetica Neue\", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme=\"light\"]) {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme=\"dark\"] {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 13px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type=\"button\"], input[type=\"submit\"], input[type=\"reset\"], .button) { min-block-size: 26px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n"};
|
package/src/index-theme.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
export const THEME_READY = 'index:theme-ready';
|
|
3
3
|
export const THEME_SET = 'index:theme-set';
|
|
4
4
|
export const THEMES = new Set(['light', 'dark']);
|
|
5
|
-
export const APPEARANCES = new Set(['base', 'compact']);
|
|
5
|
+
export const APPEARANCES = new Set(['base', 'compact', 'mimi', 'joanna']);
|
|
@@ -24,9 +24,6 @@ const NATIVE_ATTRIBUTES = {
|
|
|
24
24
|
canvas: ['width', 'height'],
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// A `${name}` template reference; `\${` stays text (Builder's runtimeValues rule).
|
|
28
|
-
const TEMPLATE_REFERENCE = /(?<!\\)\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
29
|
-
|
|
30
27
|
// Display directives of the node text: consumed by the renderer, never written as attributes.
|
|
31
28
|
const DISPLAY_ATTRIBUTES = ['format', 'mask', 'locale', 'timeZone', 'places', 'dtype'];
|
|
32
29
|
|
|
@@ -80,7 +77,7 @@ function isJavascriptUrl(value) {
|
|
|
80
77
|
/**
|
|
81
78
|
* `attrs` of an `iframe` whose `srcdoc` comes from Data, with an empty `sandbox` first: the browser shows
|
|
82
79
|
* the HTML of a datum and runs nothing of it. `srcdoc` comes from Data when it is a `^`/`=` pointer, a `==`
|
|
83
|
-
* expression
|
|
80
|
+
* expression, or when the node value is a pointer, whose datum can carry
|
|
84
81
|
* `srcdoc` in its `_wdg`. The declaration decides, so the iframe has `sandbox` while `srcdoc` is still null.
|
|
85
82
|
* A `sandbox` declared in the Source stays as declared; a literal `srcdoc` gets none. The names are read
|
|
86
83
|
* without the dialect `prefixes` (`html_`); `sandbox` takes the prefix of `srcdoc`.
|
|
@@ -94,15 +91,8 @@ export function withDataSrcdocSandbox(node, attrs, prefixes = []) {
|
|
|
94
91
|
const declared = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
95
92
|
const srcdoc = [...Object.keys(declared), ...Object.keys(attrs)].find(name => bare(name)[1] === 'srcdoc');
|
|
96
93
|
if (srcdoc === undefined || Object.keys(declared).some(name => bare(name)[1] === 'sandbox')) return attrs;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
seen.add(name);
|
|
100
|
-
return node.pointerType(raw) !== null || isExpression(raw) || templateParameters(raw)
|
|
101
|
-
.some(param => Object.hasOwn(declared, param) && !seen.has(param) && fromData(param, seen));
|
|
102
|
-
};
|
|
103
|
-
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && fromData(srcdoc, new Set()))) {
|
|
104
|
-
return attrs;
|
|
105
|
-
}
|
|
94
|
+
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc)
|
|
95
|
+
&& (node.pointerType(declared[srcdoc]) !== null || isExpression(declared[srcdoc])))) return attrs;
|
|
106
96
|
const rest = Object.fromEntries(Object.entries(attrs).filter(([name]) => bare(name)[1] !== 'sandbox'));
|
|
107
97
|
return {[`${bare(srcdoc)[0]}sandbox`]: '', ...rest};
|
|
108
98
|
}
|
|
@@ -171,34 +161,7 @@ export function displayItem(item, attrs, format = null) {
|
|
|
171
161
|
return [display(item), rest];
|
|
172
162
|
}
|
|
173
163
|
|
|
174
|
-
/** The parameter names of the `${name}` templates of `value`, in order; none for a value that is not a string. */
|
|
175
|
-
export function templateParameters(value) {
|
|
176
|
-
return typeof value === 'string' ? [...value.matchAll(TEMPLATE_REFERENCE)].map(([, name]) => name) : [];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
164
|
/** Whether `value` is a `==` expression (Q11.2). */
|
|
180
165
|
export function isExpression(value) {
|
|
181
166
|
return typeof value === 'string' && value.startsWith('==');
|
|
182
167
|
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Templates and `==` expressions do not mix (Q11.2): a template that uses a `==` attribute of the same
|
|
186
|
-
* node is an error naming both attributes; a `${…}` inside a `==` attribute or node value is an error
|
|
187
|
-
* naming it.
|
|
188
|
-
*/
|
|
189
|
-
export function requireNoExpressionTemplate(node) {
|
|
190
|
-
if (isExpression(node.value) && templateParameters(node.value).length) {
|
|
191
|
-
throw new Error(`${node.nodeTag} '${node.label}': the == node value contains a \${…} template, not accepted in a == expression`);
|
|
192
|
-
}
|
|
193
|
-
const attrs = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
194
|
-
for (const [name, raw] of Object.entries(attrs)) {
|
|
195
|
-
if (isExpression(raw) && templateParameters(raw).length) {
|
|
196
|
-
throw new Error(`${node.nodeTag} '${node.label}': '${name}' contains a \${…} template, not accepted in a == expression`);
|
|
197
|
-
}
|
|
198
|
-
for (const param of templateParameters(raw)) {
|
|
199
|
-
if (isExpression(attrs[param])) {
|
|
200
|
-
throw new Error(`${node.nodeTag} '${node.label}': the template of '${name}' uses '${param}', a == expression`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -8,7 +8,7 @@ import {HtmlBuilder, HtmlRenderer, SvgBuilder, sourceAttributeItems} from '@genr
|
|
|
8
8
|
import {GramlotSvgRenderer} from './gramlot-svg-renderer.js';
|
|
9
9
|
import {webcomponentCode} from '../webcomponent.js';
|
|
10
10
|
import {
|
|
11
|
-
SVG_NS, XHTML_NS, boundaryAttributes, displayItem, domNames, isExpression,
|
|
11
|
+
SVG_NS, XHTML_NS, boundaryAttributes, displayItem, domNames, isExpression,
|
|
12
12
|
requireNoScriptAttributes, requireStyleClassAttributes, splitNativeAttributes, textValue, withDataSrcdocSandbox, withoutBindingAttributes,
|
|
13
13
|
withoutNullValues,
|
|
14
14
|
} from './attributes.js';
|
|
@@ -31,6 +31,8 @@ export class GramlotHtmlRenderer extends HtmlRenderer {
|
|
|
31
31
|
/** HTML nodes (GramlotBuilder, HtmlBuilder) → this renderer; SVG nodes → one GramlotSvgRenderer owned by it. */
|
|
32
32
|
getRender(builder) {
|
|
33
33
|
if (!this.renders.has(builder)) {
|
|
34
|
+
// HTML/SVG subbuilders share the page's expression hook and compiler.
|
|
35
|
+
builder.evaluatePointerExpression = this.builder.evaluatePointerExpression.bind(this.builder);
|
|
34
36
|
if (builder instanceof HtmlBuilder) this.addRender(builder, this);
|
|
35
37
|
else if (builder instanceof SvgBuilder) this.addRender(builder, new GramlotSvgRenderer(builder, this));
|
|
36
38
|
}
|
|
@@ -73,10 +75,9 @@ export class GramlotHtmlRenderer extends HtmlRenderer {
|
|
|
73
75
|
/**
|
|
74
76
|
* Step 3 of Q11.2 on the attributes of `node` resolved by runtimeValues, for HTML and SVG nodes: every
|
|
75
77
|
* `==` attribute, and a `==` node value, evaluated by the page's InlineCompiler (§4.10); without a
|
|
76
|
-
* compiler they are null and nothing is written.
|
|
78
|
+
* compiler they are null and nothing is written.
|
|
77
79
|
*/
|
|
78
80
|
evaluateExpressions(node, runtimeAttrs) {
|
|
79
|
-
requireNoExpressionTemplate(node);
|
|
80
81
|
const compiler = this.inlineCompiler;
|
|
81
82
|
const evaluate = (attr, expr) => (compiler ? compiler.compileExpression(node, attr, expr)(runtimeAttrs) : null);
|
|
82
83
|
const attrs = {...runtimeAttrs};
|