@gramlot/gramlot 0.3.16 → 0.3.18

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 (102) hide show
  1. package/dist/components/editors/__init__.py +1 -1
  2. package/dist/components/editors/assets/collection.js +16162 -11689
  3. package/dist/components/editors/assets/index.js +1 -1
  4. package/dist/components/editors/grammar.json +3 -0
  5. package/dist/components/inputs/__init__.py +1 -1
  6. package/dist/components/inputs/assets/collection.js +134 -179
  7. package/dist/components/inputs/assets/index.js +1 -1
  8. package/dist/components/inputs/grammar.json +19 -0
  9. package/dist/components/layout/__init__.py +1 -1
  10. package/dist/components/layout/assets/collection.js +4643 -3481
  11. package/dist/components/layout/assets/index.js +1 -1
  12. package/dist/components/layout/grammar.json +509 -1
  13. package/dist/components/tree/__init__.py +1 -1
  14. package/dist/components/tree/assets/collection.js +306 -94
  15. package/dist/components/tree/assets/index.js +1 -1
  16. package/dist/components/tree/grammar.json +16 -0
  17. package/dist/components/typst/__init__.py +1 -1
  18. package/dist/components/typst/assets/collection.js +2 -2
  19. package/dist/components/typst/assets/index.js +1 -1
  20. package/dist/gramlot.js +2126 -506
  21. package/dist/gramlot.min.js +97 -40
  22. package/dist/runtime-notices.json +4 -0
  23. package/package.json +12 -8
  24. package/src/binding/device-resolver.js +27 -0
  25. package/src/binding/error-notifications.js +84 -0
  26. package/src/binding/remote-resolver.d.ts +18 -0
  27. package/src/binding/remote.js +11 -4
  28. package/src/binding/runtime.js +6 -2
  29. package/src/bootstrap.js +4 -4
  30. package/src/components/buttons.js +10 -3
  31. package/src/components/code-mirror-engine.js +14 -4
  32. package/src/components/code-mirror.js +2 -3
  33. package/src/components/container.js +1 -1
  34. package/src/components/date-calendar.js +1 -1
  35. package/src/components/formlet-labels.js +5 -4
  36. package/src/components/html-document.js +4 -2
  37. package/src/components/html-editor.js +2 -2
  38. package/src/components/jodit-engine.js +72 -11
  39. package/src/components/labelbox.js +19 -63
  40. package/src/components/layout.js +31 -19
  41. package/src/components/markdown-document.js +1 -1
  42. package/src/components/markdown-editor.js +2 -2
  43. package/src/components/menus.js +7 -6
  44. package/src/components/prose-mirror-engine.js +14 -1
  45. package/src/components/registry.js +2 -0
  46. package/src/components/selected-container.js +107 -14
  47. package/src/components/toolbar-overflow.js +9 -8
  48. package/src/components/transform-pane.js +140 -0
  49. package/src/components/tray-geometry.js +87 -0
  50. package/src/components/tray-pane.js +435 -0
  51. package/src/components/tray-settings.js +62 -0
  52. package/src/components/tree.js +115 -21
  53. package/src/components/typed-editor.js +1 -1
  54. package/src/components/typst-client.js +14 -13
  55. package/src/components/validation.js +1 -1
  56. package/src/components/window-surface.js +281 -0
  57. package/src/components/windows.js +32 -261
  58. package/src/device-frames.js +195 -0
  59. package/src/filesystem.d.ts +12 -5
  60. package/src/filesystem.js +8 -8
  61. package/src/gramlot.d.ts +3 -1
  62. package/src/gramlot.js +11 -4
  63. package/src/handlers/device-handler.d.ts +75 -0
  64. package/src/handlers/device-handler.js +1037 -0
  65. package/src/handlers/dom-handler.d.ts +2 -0
  66. package/src/handlers/dom-handler.js +9 -0
  67. package/src/handlers/rpc-handler.d.ts +2 -2
  68. package/src/http-transport.d.ts +3 -3
  69. package/src/http-transport.js +17 -11
  70. package/src/ide-documents.js +6 -4
  71. package/src/ide-runtime.d.ts +14 -3
  72. package/src/ide-runtime.js +123 -94
  73. package/src/index-page-runtime.d.ts +2 -2
  74. package/src/index-page-runtime.js +91 -43
  75. package/src/index-page-styles.js +1 -1
  76. package/src/index.d.ts +7 -2
  77. package/src/index.js +5 -1
  78. package/src/inout.d.ts +1 -1
  79. package/src/inout.js +5 -1
  80. package/src/mobile-environment.d.ts +6 -0
  81. package/src/mobile-environment.js +52 -0
  82. package/src/navigation-resolver.d.ts +14 -2
  83. package/src/renderer/attributes.js +5 -2
  84. package/src/renderer/drag-drop.js +5 -4
  85. package/src/renderer/gramlot-renderer.d.ts +13 -2
  86. package/src/renderer/gramlot-renderer.js +49 -13
  87. package/src/server/index-page.js +4 -4
  88. package/src/view/controls.js +48 -23
  89. package/src/view/html.js +85 -4
  90. package/src/view/labelbox.js +97 -0
  91. package/themes/gramlot-base/theme.css +10 -0
  92. package/themes/gramlot-compact/theme.css +6 -0
  93. package/themes/joanna/theme.css +6 -0
  94. package/themes/mela/theme.css +68 -15
  95. package/themes/mimi/theme.css +6 -0
  96. package/themes/palettes/compact.css +6 -0
  97. package/themes/palettes/joanna.css +6 -0
  98. package/themes/palettes/mimi.css +6 -0
  99. package/src/date-parser/civil.js +0 -61
  100. package/src/date-parser/index.d.ts +0 -18
  101. package/src/date-parser/index.js +0 -196
  102. package/src/date-parser/locales.js +0 -257
@@ -1,196 +0,0 @@
1
- /* @ts-self-types="./index.d.ts" */
2
- // Copyright 2026 Softwell S.r.l. - SPDX-License-Identifier: Apache-2.0
3
- // Semantics ported from genro-toolbox dates/period_parser.py; see PORT-0009.
4
- import {addDays, civil, monday, monthPeriod, parts, daysInMonth} from './civil.js';
5
- import {localeContext} from './locales.js';
6
-
7
- const yearPattern = /^(?:\d{4}|\d{2})$/;
8
- const dayPattern = /^\d{1,2}$/;
9
- const fail = (code, message) => ({ok: false, error: {code, message}});
10
- const unrecognized = (code = 'UNRECOGNIZED_EXPRESSION', message = 'Text is not a supported date expression.') => {
11
- throw Object.assign(new SyntaxError(message), {code});
12
- };
13
- const own = (object, key) => Object.hasOwn(object, key);
14
-
15
- function decodeYear(text, context) {
16
- if (text.length === 4) return Number(text);
17
- const lowest = context.year + context.twoDigitYearAhead - 100;
18
- return lowest + ((Number(text) - lowest) % 100 + 100) % 100;
19
- }
20
-
21
- function boundTexts(text, context) {
22
- if (text.includes(';')) {
23
- const bounds = text.split(';').map(part => part.trim());
24
- if (bounds.length !== 2) return unrecognized('INVALID_RANGE', 'A range must have exactly two endpoints.');
25
- return {bounds, range: true};
26
- }
27
- if (context.phrases('no_period').includes(text)) return {bounds: ['', ''], range: true};
28
- const to = context.phrases('to'), from = context.phrases('from');
29
- for (const word of to) {
30
- if (text.startsWith(`${word} `)) return {bounds: ['', text.slice(word.length + 1).trim()], range: true};
31
- }
32
- for (const word of to) {
33
- const separator = ` ${word} `;
34
- if (!text.includes(separator)) continue;
35
- for (const prefix of from) {
36
- if (text.startsWith(`${prefix} `)) {
37
- text = text.slice(prefix.length + 1);
38
- break;
39
- }
40
- }
41
- const bounds = text.split(separator).map(part => part.trim());
42
- if (bounds.length !== 2) return unrecognized('INVALID_RANGE', 'A range must have exactly two endpoints.');
43
- return {bounds, range: true};
44
- }
45
- for (const word of from) {
46
- if (text.startsWith(`${word} `)) return {bounds: [text.slice(word.length + 1).trim(), ''], range: true};
47
- }
48
- return {bounds: [text, text], range: false};
49
- }
50
-
51
- function keywordDate(text, context, isEnd) {
52
- const candidates = [[text, 0]];
53
- const offset = /^(.+?)\s*([+-])\s*(\d+)$/.exec(text);
54
- if (offset) candidates.push([offset[1], Number(offset[2] + offset[3])]);
55
- const shifts = {today: 0, yesterday: -1, tomorrow: 1,
56
- this_week: 0, last_week: -1, next_week: 1,
57
- this_month: 0, last_month: -1, next_month: 1};
58
- for (const [body, amount] of candidates) {
59
- for (const [key, shift] of Object.entries(shifts)) {
60
- if (!context.phrases(key).includes(body)) continue;
61
- if (key.endsWith('_week')) return addDays(monday(context.workdate), (shift + amount) * 7 + (isEnd ? 6 : 0));
62
- if (key.endsWith('_month')) {
63
- const span = monthPeriod(context.year, context.month, shift + amount);
64
- return isEnd ? span.end : span.start;
65
- }
66
- return addDays(context.workdate, shift + amount);
67
- }
68
- }
69
- return null;
70
- }
71
-
72
- function quarter(text, context, isEnd) {
73
- const entries = Object.entries(context.dictionary.quarters).sort((a, b) => b[0].length - a[0].length);
74
- for (const [name, number] of entries) {
75
- let year;
76
- if (text === name) year = null;
77
- else if (text.startsWith(name) && yearPattern.test(text.slice(name.length).trim())) {
78
- year = decodeYear(text.slice(name.length).trim(), context);
79
- } else if (text.endsWith(name) && yearPattern.test(text.slice(0, -name.length).trim())) {
80
- year = decodeYear(text.slice(0, -name.length).trim(), context);
81
- } else continue;
82
- return {year, month: isEnd ? number * 3 : number * 3 - 2};
83
- }
84
- return null;
85
- }
86
-
87
- function monthNumber(token, dictionary) {
88
- if (own(dictionary.months, token)) return dictionary.months[token];
89
- const match = /^m(\d{1,2})$/.exec(token);
90
- return match && Number(match[1]) >= 1 && Number(match[1]) <= 12 ? Number(match[1]) : null;
91
- }
92
-
93
- function namedMonth(text, context) {
94
- const tokens = text.split(/\s+/);
95
- const positions = tokens.map((token, i) => monthNumber(token, context.dictionary) ? i : -1).filter(i => i >= 0);
96
- if (!positions.length) return null;
97
- if (positions.length !== 1) return unrecognized();
98
- const position = positions[0], month = monthNumber(tokens[position], context.dictionary);
99
- const before = tokens.slice(0, position), after = tokens.slice(position + 1), others = [...before, ...after];
100
- if (others.length === 1 && context.phrases('last').includes(others[0])) {
101
- return {year: context.year - (month > context.month ? 1 : 0), month};
102
- }
103
- if (others.length === 1 && context.phrases('next').includes(others[0])) {
104
- return {year: context.year + (month < context.month ? 1 : 0), month};
105
- }
106
- if (!others.length) return {year: null, month};
107
- if (!before.length && after.length === 1 && yearPattern.test(after[0])) return {year: decodeYear(after[0], context), month};
108
- if (before.length === 1 && dayPattern.test(before[0])) {
109
- if (!after.length) return civil(context.year, month, Number(before[0]));
110
- if (after.length === 1 && yearPattern.test(after[0])) return civil(decodeYear(after[0], context), month, Number(before[0]));
111
- }
112
- if (!before.length && after.length === 2 && dayPattern.test(after[0]) && yearPattern.test(after[1])) {
113
- return civil(decodeYear(after[1], context), month, Number(after[0]));
114
- }
115
- return unrecognized();
116
- }
117
-
118
- function numericDate(text, context) {
119
- const iso = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
120
- if (iso) return civil(...iso.slice(1).map(Number));
121
- const numeric = /^(\d{1,4})[/\-. ]+(\d{1,4})[/\-. ]+(\d{1,4})$/.exec(text);
122
- const values = {};
123
- if (numeric) context.order.split('').forEach((letter, i) => { values[letter] = numeric[i + 1]; });
124
- else if (/^(?:\d{6}|\d{8})$/.test(text)) {
125
- const yearWidth = text.length === 8 ? 4 : 2;
126
- for (const letter of context.order) {
127
- const width = letter === 'Y' ? yearWidth : 2;
128
- values[letter] = text.slice(0, width);
129
- text = text.slice(width);
130
- }
131
- } else return null;
132
- if (!yearPattern.test(values.Y) || values.D.length > 2 || values.M.length > 2) return unrecognized();
133
- let day = Number(values.D), month = Number(values.M);
134
- if (numeric && month > 12 && day <= 12) [day, month] = [month, day];
135
- return civil(decodeYear(values.Y, context), month, day);
136
- }
137
-
138
- function getBound(text, context, isEnd) {
139
- if (!text) return null;
140
- const articles = context.phrases('articles');
141
- text = text.split(/\s+/).filter(token => !articles.includes(token)).join(' ');
142
- if (!text) return unrecognized();
143
- if (yearPattern.test(text)) return civil(decodeYear(text, context), isEnd ? 12 : 1, isEnd ? 31 : 1);
144
- const value = keywordDate(text, context, isEnd) ?? quarter(text, context, isEnd) ?? namedMonth(text, context);
145
- if (value !== null) return value;
146
- if (own(context.dictionary.weekdays, text)) return addDays(monday(context.workdate), context.dictionary.weekdays[text]);
147
- return numericDate(text, context) ?? unrecognized();
148
- }
149
-
150
- function startDate(start, end, context) {
151
- if (start === null || typeof start === 'string') return start;
152
- let year = start.year ?? context.year;
153
- const endYear = typeof end === 'string' ? parts(end)[0] : end?.year;
154
- const endMonth = typeof end === 'string' ? parts(end)[1] : end?.month;
155
- if (endYear) {
156
- if (year > endYear) year = endYear;
157
- if (year === endYear && start.month > endMonth) year--;
158
- }
159
- return civil(year, start.month, 1);
160
- }
161
-
162
- function endDate(end, start, context) {
163
- if (end === null || typeof end === 'string') return end;
164
- let year = end.year ?? context.year;
165
- if (start !== null) {
166
- const [startYear, startMonth] = parts(start);
167
- if (year < startYear) year = startYear;
168
- if (year === startYear && startMonth > end.month) year++;
169
- }
170
- return civil(year, end.month, daysInMonth(year, end.month));
171
- }
172
-
173
- /** Parse a complete date expression using Toolbox semantics and structured JS outcomes. */
174
- export function parseDateExpression(text, options = {}) {
175
- if (!options || typeof options !== 'object' || Array.isArray(options)) return fail('INVALID_CONTEXT', 'Options must provide a civil workdate and supported locale.');
176
- let context;
177
- try {
178
- const {locale = 'it-IT', workdate, twoDigitYearAhead = 20} = options;
179
- const [year, month] = parts(workdate);
180
- if (!Number.isInteger(twoDigitYearAhead) || twoDigitYearAhead < 0 || twoDigitYearAhead > 99) throw new RangeError('twoDigitYearAhead must be an integer from 0 to 99.');
181
- context = {...localeContext(locale), workdate, year, month, twoDigitYearAhead};
182
- } catch (error) { return fail('INVALID_CONTEXT', error.message); }
183
- if (typeof text !== 'string') return fail('INVALID_INPUT', 'Expression must be a string.');
184
- try {
185
- const expression = text.toLowerCase().trim().replaceAll(',', '');
186
- const {bounds, range} = boundTexts(expression, context);
187
- const right = getBound(bounds[1], context, true), left = getBound(bounds[0], context, false);
188
- const start = startDate(left, right, context), end = endDate(right, start, context);
189
- if (!range && typeof left === 'string' && start === end) return {ok: true, kind: 'date', date: start};
190
- return {ok: true, kind: 'period', start, end};
191
- } catch (error) {
192
- if (error instanceof RangeError) return fail('INVALID_DATE', error.message);
193
- if (error instanceof SyntaxError) return fail(error.code, error.message);
194
- throw error;
195
- }
196
- }
@@ -1,257 +0,0 @@
1
- // Copyright 2026 Softwell S.r.l. - SPDX-License-Identifier: Apache-2.0
2
- // Vocabulary from genro-toolbox dfb7322a53a2f9030d6baaadfbb87028559672fd.
3
- // Keep the upstream JSON contents unchanged; see PORT-0009 for refresh/fixture provenance.
4
- const locales = {
5
- "it": {
6
- "months": {
7
- "gennaio": 1,
8
- "febbraio": 2,
9
- "marzo": 3,
10
- "aprile": 4,
11
- "maggio": 5,
12
- "giugno": 6,
13
- "luglio": 7,
14
- "agosto": 8,
15
- "settembre": 9,
16
- "ottobre": 10,
17
- "novembre": 11,
18
- "dicembre": 12,
19
- "gen": 1,
20
- "feb": 2,
21
- "mar": 3,
22
- "apr": 4,
23
- "mag": 5,
24
- "giu": 6,
25
- "lug": 7,
26
- "ago": 8,
27
- "set": 9,
28
- "ott": 10,
29
- "nov": 11,
30
- "dic": 12
31
- },
32
- "weekdays": {
33
- "lunedì": 0,
34
- "martedì": 1,
35
- "mercoledì": 2,
36
- "giovedì": 3,
37
- "venerdì": 4,
38
- "sabato": 5,
39
- "domenica": 6,
40
- "lun": 0,
41
- "mar": 1,
42
- "mer": 2,
43
- "gio": 3,
44
- "ven": 4,
45
- "sab": 5,
46
- "dom": 6
47
- },
48
- "quarters": {
49
- "1º trimestre": 1,
50
- "2º trimestre": 2,
51
- "3º trimestre": 3,
52
- "4º trimestre": 4,
53
- "1° trimestre": 1,
54
- "2° trimestre": 2,
55
- "3° trimestre": 3,
56
- "4° trimestre": 4,
57
- "t1": 1,
58
- "t2": 2,
59
- "t3": 3,
60
- "t4": 4,
61
- "q1": 1,
62
- "q2": 2,
63
- "q3": 3,
64
- "q4": 4
65
- },
66
- "keywords": {
67
- "today": [
68
- "oggi"
69
- ],
70
- "yesterday": [
71
- "ieri"
72
- ],
73
- "tomorrow": [
74
- "domani"
75
- ],
76
- "this_week": [
77
- "questa settimana",
78
- "settimana"
79
- ],
80
- "last_week": [
81
- "settimana scorsa"
82
- ],
83
- "next_week": [
84
- "settimana prossima"
85
- ],
86
- "this_month": [
87
- "questo mese",
88
- "mese"
89
- ],
90
- "last_month": [
91
- "mese scorso"
92
- ],
93
- "next_month": [
94
- "mese prossimo"
95
- ],
96
- "last": [
97
- "scorso",
98
- "scorsa"
99
- ],
100
- "next": [
101
- "prossimo",
102
- "prossima"
103
- ],
104
- "articles": [
105
- "il",
106
- "lo",
107
- "la"
108
- ],
109
- "from": [
110
- "da",
111
- "dal",
112
- "dalla",
113
- "tra",
114
- "fra"
115
- ],
116
- "to": [
117
- "a",
118
- "al",
119
- "alla",
120
- "e"
121
- ],
122
- "no_period": [
123
- "-",
124
- "senza periodo",
125
- "sempre"
126
- ]
127
- },
128
- "date_order": {
129
- "default": "DMY"
130
- }
131
- },
132
- "en": {
133
- "months": {
134
- "january": 1,
135
- "february": 2,
136
- "march": 3,
137
- "april": 4,
138
- "may": 5,
139
- "june": 6,
140
- "july": 7,
141
- "august": 8,
142
- "september": 9,
143
- "october": 10,
144
- "november": 11,
145
- "december": 12,
146
- "jan": 1,
147
- "feb": 2,
148
- "mar": 3,
149
- "apr": 4,
150
- "jun": 6,
151
- "jul": 7,
152
- "aug": 8,
153
- "sep": 9,
154
- "oct": 10,
155
- "nov": 11,
156
- "dec": 12
157
- },
158
- "weekdays": {
159
- "monday": 0,
160
- "tuesday": 1,
161
- "wednesday": 2,
162
- "thursday": 3,
163
- "friday": 4,
164
- "saturday": 5,
165
- "sunday": 6,
166
- "mon": 0,
167
- "tue": 1,
168
- "wed": 2,
169
- "thu": 3,
170
- "fri": 4,
171
- "sat": 5,
172
- "sun": 6
173
- },
174
- "quarters": {
175
- "1st quarter": 1,
176
- "2nd quarter": 2,
177
- "3rd quarter": 3,
178
- "4th quarter": 4,
179
- "q1": 1,
180
- "q2": 2,
181
- "q3": 3,
182
- "q4": 4
183
- },
184
- "keywords": {
185
- "today": [
186
- "today"
187
- ],
188
- "yesterday": [
189
- "yesterday"
190
- ],
191
- "tomorrow": [
192
- "tomorrow"
193
- ],
194
- "this_week": [
195
- "this week",
196
- "week"
197
- ],
198
- "last_week": [
199
- "last week"
200
- ],
201
- "next_week": [
202
- "next week"
203
- ],
204
- "this_month": [
205
- "this month",
206
- "month"
207
- ],
208
- "last_month": [
209
- "last month"
210
- ],
211
- "next_month": [
212
- "next month"
213
- ],
214
- "last": [
215
- "last"
216
- ],
217
- "next": [
218
- "next"
219
- ],
220
- "articles": [
221
- "the"
222
- ],
223
- "from": [
224
- "from",
225
- "between"
226
- ],
227
- "to": [
228
- "to",
229
- "and"
230
- ],
231
- "no_period": [
232
- "no period",
233
- "always"
234
- ]
235
- },
236
- "date_order": {
237
- "default": "MDY",
238
- "GB": "DMY",
239
- "AU": "DMY",
240
- "IE": "DMY",
241
- "NZ": "DMY",
242
- "IN": "DMY"
243
- }
244
- }
245
- };
246
-
247
- export function localeContext(locale) {
248
- if (typeof locale !== 'string') throw new RangeError('A supported locale is required.');
249
- const tag = locale.replaceAll('-', '_');
250
- const split = tag.indexOf('_');
251
- const language = (split < 0 ? tag : tag.slice(0, split)).toLowerCase();
252
- const region = (split < 0 ? '' : tag.slice(split + 1)).toUpperCase();
253
- if (!Object.hasOwn(locales, language)) throw new RangeError(`Unsupported locale: ${locale}`);
254
- const dictionary = locales[language];
255
- const phrases = key => [...new Set([...dictionary.keywords[key], ...locales.en.keywords[key]])];
256
- return {dictionary, phrases, order: dictionary.date_order[region] ?? dictionary.date_order.default};
257
- }