@vermeulen.solutions/eventual 0.0.0-stage → 0.18.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/LICENSE +21 -0
- package/README.md +137 -2
- package/astro/EventList.astro +57 -0
- package/astro/admin.d.mts +3 -0
- package/astro/admin.mjs +158 -0
- package/astro/blueprint.d.mts +51 -0
- package/astro/blueprint.mjs +236 -0
- package/astro/cache.ts +82 -0
- package/astro/descriptor.mjs +7 -0
- package/astro/editor-compat.mjs +197 -0
- package/astro/editor-i18n.d.mts +8 -0
- package/astro/editor-i18n.mjs +157 -0
- package/astro/event-details.ts +29 -0
- package/astro/event-list.ts +56 -0
- package/astro/feed.ts +201 -0
- package/astro/install.d.mts +9 -0
- package/astro/install.mjs +66 -0
- package/astro/schema.ts +88 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +1585 -0
- package/dist/plugin.d.mts +6 -0
- package/dist/plugin.mjs +13 -0
- package/docs/collection-setup.md +46 -0
- package/docs/history.md +16 -0
- package/docs/native-modernization.md +99 -0
- package/docs/public-feed-caching.md +259 -0
- package/docs/registry-installation.md +13 -0
- package/docs/release-notes-0.14.0.md +27 -0
- package/docs/release-notes-0.14.1.md +40 -0
- package/docs/release-notes-0.15.0.md +18 -0
- package/docs/release-notes-0.16.0.md +7 -0
- package/docs/release-notes-0.17.0.md +7 -0
- package/docs/release-notes-0.18.0.md +8 -0
- package/docs/release-notes-0.18.1.md +7 -0
- package/docs/upgrade-0.13.0.md +21 -0
- package/docs/user-guide.md +40 -0
- package/emdash-plugin.jsonc +77 -0
- package/package.json +142 -4
- package/scripts/check-editor-installation.mjs +32 -0
- package/scripts/export-native-schema.mjs +28 -0
- package/scripts/upgrade-native-editor.mjs +296 -0
- package/src/domain/calendar-links.ts +80 -0
- package/src/domain/category.ts +32 -0
- package/src/domain/collections.ts +101 -0
- package/src/domain/date-time.ts +220 -0
- package/src/domain/description.ts +108 -0
- package/src/domain/event-data.ts +217 -0
- package/src/domain/event-expansion.ts +305 -0
- package/src/domain/event.ts +195 -0
- package/src/domain/icalendar.ts +165 -0
- package/src/domain/image.ts +18 -0
- package/src/domain/invocation-budget.ts +56 -0
- package/src/domain/messages.ts +8 -0
- package/src/domain/migration.ts +666 -0
- package/src/domain/native-calendar.ts +256 -0
- package/src/domain/native-references.ts +41 -0
- package/src/domain/native-source.ts +261 -0
- package/src/domain/native-validation.ts +366 -0
- package/src/domain/occurrences.ts +54 -0
- package/src/domain/portable-text.ts +180 -0
- package/src/domain/public-cache.ts +24 -0
- package/src/domain/recurrence-rule.ts +34 -0
- package/src/domain/recurrence.ts +350 -0
- package/src/domain/request-memo.ts +8 -0
- package/src/domain/schedule-history.ts +14 -0
- package/src/domain/text.ts +2 -0
- package/src/domain/time-entry.ts +23 -0
- package/src/domain/venue-adapter.ts +101 -0
- package/src/domain/venue.ts +42 -0
- package/src/public-event.ts +88 -0
- package/src/schema/blueprint.ts +315 -0
- package/src/storage.ts +257 -0
- package/transfer/index.d.mts +13 -0
- package/transfer/index.mjs +155 -0
package/astro/cache.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { PUBLIC_FEED_CACHE_CEILING_MS, type PublicFeedCache } from '../src/domain/public-cache';
|
|
2
|
+
import { calendarDateKey, isDateOnly, isValidTimeZone, localDateTimeToInstant } from '../src/domain/date-time';
|
|
3
|
+
import type { PublicEvent, PublicFeed } from './feed';
|
|
4
|
+
|
|
5
|
+
export type { PublicFeedCache };
|
|
6
|
+
|
|
7
|
+
function instant(value: unknown): number {
|
|
8
|
+
if (typeof value !== 'string') return NaN;
|
|
9
|
+
const time = Date.parse(value);
|
|
10
|
+
return Number.isFinite(time) && new Date(time).toISOString() === value ? time : NaN;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Unknown/old metadata still renders, but cannot authorize cache storage. */
|
|
14
|
+
export function parsePublicFeedCache(value: unknown): PublicFeedCache | undefined {
|
|
15
|
+
if (!value || typeof value !== 'object') return;
|
|
16
|
+
const cache = value as PublicFeedCache;
|
|
17
|
+
const generated = instant(cache.generatedAt), expires = instant(cache.expiresAt);
|
|
18
|
+
if (cache.version !== 1 || !Array.isArray(cache.dependencies) || cache.dependencies.length < 2 || cache.dependencies.length > 4
|
|
19
|
+
|| !cache.dependencies.every(tag => typeof tag === 'string' && /^(?:[a-z][a-z0-9_]{0,62}|emdash:settings)$/.test(tag))
|
|
20
|
+
|| !cache.dependencies.includes('emdash:settings')
|
|
21
|
+
|| !cache.dependencies.some(tag => tag !== 'emdash:settings')
|
|
22
|
+
|| !Number.isFinite(generated) || !Number.isFinite(expires)
|
|
23
|
+
|| expires <= generated || expires - generated > PUBLIC_FEED_CACHE_CEILING_MS) return;
|
|
24
|
+
return { version: 1, dependencies: [...new Set(cache.dependencies)], generatedAt: cache.generatedAt, expiresAt: cache.expiresAt };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Explicit host TTL required. A failed split, stale metadata or invalid boundary disables storage. */
|
|
28
|
+
export function publicFeedCacheOptions(
|
|
29
|
+
feeds: readonly Pick<PublicFeed, 'ok' | 'cache'>[],
|
|
30
|
+
options: { maxAge: number; now?: number; boundaries?: readonly string[] },
|
|
31
|
+
): false | { tags: string[]; maxAge: number; swr: 0 } {
|
|
32
|
+
const now = options.now ?? Date.now();
|
|
33
|
+
if (!feeds.length || !Number.isFinite(now) || !Number.isFinite(options.maxAge) || options.maxAge < 1) return false;
|
|
34
|
+
let remaining = options.maxAge * 1000;
|
|
35
|
+
const tags = new Set<string>();
|
|
36
|
+
for (const feed of feeds) {
|
|
37
|
+
const cache = feed.ok === true ? parsePublicFeedCache(feed.cache) : undefined;
|
|
38
|
+
if (!cache || instant(cache.generatedAt) > now) return false;
|
|
39
|
+
remaining = Math.min(remaining, instant(cache.expiresAt) - now);
|
|
40
|
+
for (const tag of cache.dependencies) tags.add(tag);
|
|
41
|
+
}
|
|
42
|
+
for (const boundary of options.boundaries ?? []) {
|
|
43
|
+
const time = instant(boundary);
|
|
44
|
+
if (!Number.isFinite(time)) return false;
|
|
45
|
+
remaining = Math.min(remaining, time - now);
|
|
46
|
+
}
|
|
47
|
+
const maxAge = Math.floor(remaining / 1000);
|
|
48
|
+
return maxAge >= 1 ? { tags: [...tags], maxAge, swr: 0 } : false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Optional renderer boundary for upcoming/ongoing/ended labels. All-day end is inclusive. */
|
|
52
|
+
export function publicEventTimeBoundary(events: readonly PublicEvent[], now = Date.now()): string | undefined {
|
|
53
|
+
if (!Number.isFinite(now)) throw new Error('Invalid clock');
|
|
54
|
+
let next = Infinity;
|
|
55
|
+
for (const event of events) {
|
|
56
|
+
let boundaries: number[];
|
|
57
|
+
if (event.allDay) {
|
|
58
|
+
if (!isDateOnly(event.start) || !isDateOnly(event.end)) throw new Error('Invalid all-day dates');
|
|
59
|
+
const end = new Date(event.end + 'T00:00:00Z');
|
|
60
|
+
end.setUTCDate(end.getUTCDate() + 1);
|
|
61
|
+
boundaries = [event.start, end.toISOString().slice(0, 10)].map(day => {
|
|
62
|
+
const result = localDateTimeToInstant(day + 'T00:00', event.timezone);
|
|
63
|
+
if (!result.value) throw new Error('Cannot resolve all-day timezone boundary');
|
|
64
|
+
return Date.parse(result.value);
|
|
65
|
+
});
|
|
66
|
+
} else boundaries = [Date.parse(event.start), Date.parse(event.end)];
|
|
67
|
+
if (!boundaries.every(Number.isFinite)) throw new Error('Invalid event time boundary');
|
|
68
|
+
for (const boundary of boundaries) if (boundary > now) next = Math.min(next, boundary);
|
|
69
|
+
}
|
|
70
|
+
return Number.isFinite(next) ? new Date(next).toISOString() : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Next local date change for renderers that group or filter by today's date. */
|
|
74
|
+
export function publicCalendarDateBoundary(timezone: string, now = Date.now()): string {
|
|
75
|
+
if (!isValidTimeZone(timezone) || !Number.isFinite(now)) throw new Error('Invalid timezone or clock');
|
|
76
|
+
const day = calendarDateKey(new Date(now).toISOString(), false, timezone);
|
|
77
|
+
const date = new Date(day + 'T00:00:00Z');
|
|
78
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
79
|
+
const result = localDateTimeToInstant(date.toISOString().slice(0, 10) + 'T00:00', timezone);
|
|
80
|
+
if (!result.value) throw new Error('Cannot resolve timezone midnight');
|
|
81
|
+
return result.value;
|
|
82
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import pkg from "../package.json" with { type: "json" };
|
|
2
|
+
export function eventualEditor(version = pkg.version) {
|
|
3
|
+
return { id: "eventual-editor", version, format: "native", entrypoint: "@vermeulen.solutions/eventual/admin", adminEntry: "@vermeulen.solutions/eventual/admin" };
|
|
4
|
+
}
|
|
5
|
+
export function createPlugin() {
|
|
6
|
+
return { id: "eventual-editor", version: pkg.version, capabilities: [], allowedHosts: [], storage: {}, hooks: {}, routes: {}, admin: {} };
|
|
7
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy source-install transform for `@vermeulen.solutions/eventual/install`. Registry installs
|
|
3
|
+
* never execute this file; the host renders plugin panels directly.
|
|
4
|
+
*
|
|
5
|
+
* Blocks 1.2-1.3 render a form block as <form> inside the content editor's
|
|
6
|
+
* <form>. Blocks 1.4+ render a div[role="group"] with its own Enter handling.
|
|
7
|
+
* This patches both shapes plus Eventual-specific form state and date-label
|
|
8
|
+
* behaviour that the host renderer does not provide.
|
|
9
|
+
*/
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
const presentationModule = fileURLToPath(new URL("./editor-i18n.mjs",import.meta.url)).replaceAll("\\","/");
|
|
12
|
+
export function patchEmbeddedBlockForms(source) {
|
|
13
|
+
const marker = "function FormBlockComponent({ block, onAction }) {";
|
|
14
|
+
const start = source.indexOf(marker);
|
|
15
|
+
if (start < 0)
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Unsupported EmDash Block Kit renderer: FormBlockComponent changed.",
|
|
18
|
+
);
|
|
19
|
+
const end = source.indexOf("\n//#endregion", start);
|
|
20
|
+
if (end < 0) throw new Error("Unsupported EmDash Block Kit form boundary.");
|
|
21
|
+
let component = source.slice(start, end);
|
|
22
|
+
const initializer =
|
|
23
|
+
"const [values, setValues] = useState(() => getInitialValues(block.fields));";
|
|
24
|
+
if (!component.includes(initializer))
|
|
25
|
+
throw new Error("Unsupported EmDash Block Kit form state initializer.");
|
|
26
|
+
component = component.replace(
|
|
27
|
+
initializer,
|
|
28
|
+
initializer +
|
|
29
|
+
"\n useEffect(() => setValues(getInitialValues(block.fields)), [block.fields]);",
|
|
30
|
+
);
|
|
31
|
+
const legacyForm =
|
|
32
|
+
component.includes('jsxs("form", {') &&
|
|
33
|
+
component.includes("onSubmit: handleSubmit,") &&
|
|
34
|
+
component.includes('type: "submit",') &&
|
|
35
|
+
component.includes("e.preventDefault();");
|
|
36
|
+
const modernForm =
|
|
37
|
+
!component.includes('jsxs("form", {') &&
|
|
38
|
+
component.includes('role: "group"') &&
|
|
39
|
+
component.includes('type: "button"') &&
|
|
40
|
+
component.includes("onClick: handleClick");
|
|
41
|
+
if (!legacyForm && !modernForm)
|
|
42
|
+
throw new Error("Unsupported EmDash Block Kit form renderer.");
|
|
43
|
+
const fieldKey = "}, field.action_id);";
|
|
44
|
+
if (!component.includes(fieldKey))
|
|
45
|
+
throw new Error("Unsupported EmDash Block Kit form field key.");
|
|
46
|
+
component = component.replace(
|
|
47
|
+
fieldKey,
|
|
48
|
+
'}, field.action_id + JSON.stringify(field.initial_value));',
|
|
49
|
+
);
|
|
50
|
+
if (legacyForm) {
|
|
51
|
+
for (const needle of [
|
|
52
|
+
"e.preventDefault();",
|
|
53
|
+
'jsxs("form", {',
|
|
54
|
+
"onSubmit: handleSubmit,",
|
|
55
|
+
'type: "submit",',
|
|
56
|
+
]) {
|
|
57
|
+
if (!component.includes(needle))
|
|
58
|
+
throw new Error("Unsupported EmDash Block Kit form: " + needle);
|
|
59
|
+
}
|
|
60
|
+
component = component.replace(
|
|
61
|
+
"e.preventDefault();",
|
|
62
|
+
`e.preventDefault();
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
const root=e.currentTarget.closest('[data-eventual-block-form]');
|
|
65
|
+
const invalid=root?.querySelector(':invalid');
|
|
66
|
+
if (invalid) { invalid.reportValidity?.(); return; }`,
|
|
67
|
+
);
|
|
68
|
+
component = component
|
|
69
|
+
.replace('jsxs("form", {', 'jsxs("div", {')
|
|
70
|
+
.replace(
|
|
71
|
+
"onSubmit: handleSubmit,",
|
|
72
|
+
`role: "group",
|
|
73
|
+
"data-eventual-block-form": "",
|
|
74
|
+
onKeyDown: (event) => {
|
|
75
|
+
if (event.key === "Enter" && !event.defaultPrevented && !event.isComposing && event.target.tagName !== "TEXTAREA" && event.target.tagName !== "BUTTON" && event.target.getAttribute("role") !== "combobox") handleSubmit(event);
|
|
76
|
+
},`,
|
|
77
|
+
)
|
|
78
|
+
.replace('type: "submit",', 'type: "button", onClick: handleSubmit,');
|
|
79
|
+
}
|
|
80
|
+
let patched = source.slice(0, start) + component + source.slice(end);
|
|
81
|
+
// The 1.2/1.3 renderer omits the option key, producing warnings on every
|
|
82
|
+
// venue choice. Use its stable value, including the empty "no venue" option.
|
|
83
|
+
const optionKey = "children: item.label\n\t\t})";
|
|
84
|
+
if (patched.includes(optionKey))
|
|
85
|
+
patched = patched.replace(
|
|
86
|
+
optionKey,
|
|
87
|
+
"children: item.label\n\t\t}, item.value)",
|
|
88
|
+
);
|
|
89
|
+
const dateMarker =
|
|
90
|
+
"function DateInputElementComponent({ element, onAction, onChange }) {";
|
|
91
|
+
const dateStart = patched.indexOf(dateMarker),
|
|
92
|
+
dateEnd = patched.indexOf("\n//#endregion", dateStart);
|
|
93
|
+
if (dateStart < 0 || dateEnd < 0)
|
|
94
|
+
throw new Error("Unsupported Block Kit date input.");
|
|
95
|
+
const date = patched.slice(dateStart, dateEnd);
|
|
96
|
+
if (!date.includes('jsx("label", {') || !date.includes('type: "date",'))
|
|
97
|
+
throw new Error("Unsupported Block Kit date label.");
|
|
98
|
+
patched =
|
|
99
|
+
patched.slice(0, dateStart) +
|
|
100
|
+
date
|
|
101
|
+
.replace(dateMarker, dateMarker + "\n const eventualDateId=useId();")
|
|
102
|
+
.replace('jsx("label", {', 'jsx("label", { htmlFor:eventualDateId,')
|
|
103
|
+
.replace('type: "date",', 'type: "date", id:eventualDateId,') +
|
|
104
|
+
patched.slice(dateEnd);
|
|
105
|
+
return addUseIdImport(patched);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function addUseIdImport(source) {
|
|
109
|
+
const reactImport = /import \{([^}]+)\} from "react";/;
|
|
110
|
+
const match = source.match(reactImport);
|
|
111
|
+
if (!match) throw new Error("Unsupported Block Kit React import.");
|
|
112
|
+
const names = match[1].split(",").map((name) => name.trim());
|
|
113
|
+
if (names.includes("useId")) return source;
|
|
114
|
+
names.push("useId");
|
|
115
|
+
return source.replace(
|
|
116
|
+
reactImport,
|
|
117
|
+
`import { ${names.join(", ")} } from "react";`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
export function eventualEditorCompatibility() {
|
|
121
|
+
let command = "serve";
|
|
122
|
+
return {
|
|
123
|
+
name: "eventual-embedded-block-forms-1.0.1",
|
|
124
|
+
enforce: "pre",
|
|
125
|
+
config(_config, env = { command: "serve" }) {
|
|
126
|
+
command = env.command ?? "serve";
|
|
127
|
+
// Keep core's admin prebundle (including its CommonJS dependencies) and
|
|
128
|
+
// apply presentation before optimization in dev. Production builds use
|
|
129
|
+
// the regular transform below; applying both duplicates the admin module.
|
|
130
|
+
return { optimizeDeps: { exclude: ["@emdash-cms/blocks"], rolldownOptions: {plugins:[{name:"eventual-admin-presentation-1.0.1", transform(source,id) {
|
|
131
|
+
if (command !== "serve") return null;
|
|
132
|
+
if (id.replaceAll("\\", "/").endsWith("/@emdash-cms/admin/dist/index.js")) return {code:patchEventualPresentation(source),map:null};
|
|
133
|
+
return null;
|
|
134
|
+
}}]} } };
|
|
135
|
+
},
|
|
136
|
+
transform(source, id) {
|
|
137
|
+
const path = id.replaceAll("\\", "/").split("?")[0];
|
|
138
|
+
if (path.endsWith("/@emdash-cms/admin/dist/index.js"))
|
|
139
|
+
return command === "serve"
|
|
140
|
+
? null
|
|
141
|
+
: { code: patchEventualPresentation(source), map: null };
|
|
142
|
+
if (
|
|
143
|
+
!id
|
|
144
|
+
.replaceAll("\\", "/")
|
|
145
|
+
.split("?")[0]
|
|
146
|
+
.endsWith("/@emdash-cms/blocks/dist/index.js")
|
|
147
|
+
)
|
|
148
|
+
return null;
|
|
149
|
+
return { code: patchEmbeddedBlockForms(source), map: null };
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Presentation adapter for the tested admin build. RPC and receipts stay untouched. */
|
|
155
|
+
export function patchEventualPresentation(source) {
|
|
156
|
+
const original = 'import { BlockRenderer, isSafePluginPagePath, normalizePluginPagePath } from "@emdash-cms/blocks";';
|
|
157
|
+
const panel = 'function SandboxedContentEditorPanel({ pluginId, panelId, title, collection, entryId, locale, versionToken, draftAccess, captureDraft, onDraftResponse, onEntryRefresh, reserveHeaderEnd = false }) {';
|
|
158
|
+
const fieldLabel = 'return field?.label || slug.charAt(0).toUpperCase() + slug.slice(1);';
|
|
159
|
+
const preview = 'function EditorDraftPatchPreview({ operations, fields, currentValues, onApply, onClose }) {';
|
|
160
|
+
const editPage = 'function ContentEditPage() {';
|
|
161
|
+
if (!source.includes(original) || !source.includes(panel) || !source.includes(fieldLabel) || !source.includes(editPage)) throw new Error("Unsupported EmDash admin presentation adapter. Use the tested compatibility matrix.");
|
|
162
|
+
let patched=source.replace(original, original.replace("{ BlockRenderer,", "{ BlockRenderer as EventualOriginalBlockRenderer,") + `
|
|
163
|
+
import { localizeEventualBlocks, draftSummary as eventualDraftSummary, editorText as eventualEditorText, loadEditorCatalog as eventualLoadCatalog, onEditorCatalog as eventualOnCatalog } from ${JSON.stringify(presentationModule)};
|
|
164
|
+
function BlockRenderer(props) {
|
|
165
|
+
const {locale}=useLocale();
|
|
166
|
+
const [eventualCatalogTick,eventualSetCatalogTick]=React$1.useState(0);
|
|
167
|
+
React$1.useEffect(()=>{ const off=eventualOnCatalog(()=>eventualSetCatalogTick(n=>n+1)); eventualLoadCatalog(locale); return off; },[locale]);
|
|
168
|
+
const blocks=React$1.useMemo(()=>localizeEventualBlocks(props.blocks, locale), [props.blocks,locale,eventualCatalogTick]);
|
|
169
|
+
return jsx(EventualOriginalBlockRenderer, {...props,blocks});
|
|
170
|
+
}`)
|
|
171
|
+
.replace(panel, panel + '\n const {locale: eventualUiLocale}=useLocale();\n if(pluginId === "eventual") title=eventualEditorText(title,eventualUiLocale);')
|
|
172
|
+
.replace(fieldLabel, 'const label=field?.label || slug.charAt(0).toUpperCase() + slug.slice(1); return field?.options?.eventualEditor ? eventualEditorText(label,i18n.locale) : label;')
|
|
173
|
+
// ContentEditPage's local i18n is the content configuration, not Lingui.
|
|
174
|
+
.replace(editPage,editPage+'\n const {locale:eventualPageUiLocale}=useLocale();')
|
|
175
|
+
.replace('description: error instanceof Error ? error.message : _t4({', 'description: error instanceof Error ? (collectionFields.start?.options?.eventualEditor ? eventualEditorText(error.message,eventualPageUiLocale) : error.message) : _t4({')
|
|
176
|
+
.replace(preview, preview + '\n const {locale: eventualPreviewLocale}=useLocale(); const eventualPreview=fields.start?.options?.eventualEditor===true;')
|
|
177
|
+
.replace('function EditorDraftPatchPreview({ operations, fields, currentValues, onApply, onClose }) {\n const {locale: eventualPreviewLocale}=useLocale(); const eventualPreview=fields.start?.options?.eventualEditor===true;\n\tconst { _: _t } = useLingui();', preview + '\n const {locale: eventualPreviewLocale}=useLocale(); const eventualPreview=fields.start?.options?.eventualEditor===true;\n const {_: eventualOriginalT}=useLingui(); const _t=eventualPreview ? message=>eventualEditorText(eventualOriginalT(message), eventualPreviewLocale):eventualOriginalT;')
|
|
178
|
+
.replace('children: fields[operation.field]?.label ?? operation.field', 'children: eventualPreview ? eventualEditorText(fields[operation.field]?.label ?? operation.field,eventualPreviewLocale) : fields[operation.field]?.label ?? operation.field')
|
|
179
|
+
.replace('children: summarize(currentValues[operation.field])', 'children: eventualPreview ? eventualDraftSummary(operation.field,currentValues[operation.field],eventualPreviewLocale,currentValues.timezone) : summarize(currentValues[operation.field])')
|
|
180
|
+
.replace('children: summarize(operation.op === "clear" ? null : operation.value)', 'children: eventualPreview ? eventualDraftSummary(operation.field,operation.op === "clear" ? null : operation.value,eventualPreviewLocale,currentValues.timezone) : summarize(operation.op === "clear" ? null : operation.value)');
|
|
181
|
+
const editorStart=patched.indexOf('function ContentEditor({'), editorEnd=patched.indexOf('\n//#endregion',editorStart);
|
|
182
|
+
if(editorStart<0 || editorEnd<0) throw new Error("Unsupported content editor boundary.");
|
|
183
|
+
const editor=patched.slice(editorStart,editorEnd).replaceAll('jsx(PublishActions, {','jsx(PublishActions, { eventualUi:Object.values(fields).some(field=>field.options?.eventualEditor===true),').replaceAll('jsx(SettingsActionBar, {','jsx(SettingsActionBar, { eventualUi:Object.values(fields).some(field=>field.options?.eventualEditor===true),');
|
|
184
|
+
patched=patched.slice(0,editorStart)+editor+patched.slice(editorEnd);
|
|
185
|
+
// Admin 1.2/1.3 use SettingsActionBar; 1.4 removed it. Patch it only when present.
|
|
186
|
+
const barStart=patched.indexOf('function SettingsActionBar({');
|
|
187
|
+
if(barStart>=0){
|
|
188
|
+
const barEnd=patched.indexOf('\nfunction ',barStart+1);
|
|
189
|
+
if(barEnd<0) throw new Error("Unsupported settings action bar boundary.");
|
|
190
|
+
patched=patched.slice(0,barStart)+patched.slice(barStart,barEnd).replace('jsx(PublishActions, {','jsx(PublishActions, { eventualUi,')+patched.slice(barEnd);
|
|
191
|
+
patched=patched.replace('function SettingsActionBar({ collectionLabel,','function SettingsActionBar({ eventualUi=false, collectionLabel,');
|
|
192
|
+
if(!patched.includes('function SettingsActionBar({ eventualUi=false, collectionLabel,')) throw new Error("Unsupported settings action bar signature.");
|
|
193
|
+
}
|
|
194
|
+
const publishPattern=/function PublishActions\(\{ collectionLabel, (isNew, isLive, hasPendingChanges, publishingState, isPending, disabled, onPublish, onUnpublish, onMenuOpenChange, size, (?:fullWidth|compact)) \}\) \{\n\tconst \{ _: _t4 \} = useLingui\(\);/;
|
|
195
|
+
if(!publishPattern.test(patched)) throw new Error("Unsupported publish actions signature.");
|
|
196
|
+
return patched.replace(publishPattern, (_match, props) => `function PublishActions({ eventualUi=false, collectionLabel, ${props} }) {\n const {locale: eventualPublishLocale}=useLocale(); const {_:eventualPublishT}=useLingui(); const _t4=eventualUi ? message=>eventualEditorText(eventualPublishT(message),eventualPublishLocale):eventualPublishT;`);
|
|
197
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function editorText(value: string, locale?: string): string;
|
|
2
|
+
export function localizeEventualBlocks(blocks: unknown[], locale: string): unknown[];
|
|
3
|
+
export function draftSummary(field: string, source: unknown, locale: string, timezone?: string): string;
|
|
4
|
+
export function fillFrenchCoreMessages(i18n: unknown): void;
|
|
5
|
+
/** Load the catalog for a UI locale (English needs none); editorText translates once it resolves. */
|
|
6
|
+
export function loadEditorCatalog(locale: string | undefined): Promise<void>;
|
|
7
|
+
/** Subscribe to catalog arrivals (to re-render); returns an unsubscribe function. */
|
|
8
|
+
export function onEditorCatalog(listener: () => void): () => void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/** Presentation only: never translate stored values, IDs, patches, or editorial rows. */
|
|
2
|
+
import { LOCALES, resolveLocale, textTranslator } from "@vermeulen.solutions/eventual-locales";
|
|
3
|
+
|
|
4
|
+
// Site code (not the sandbox): catalogs ship with the npm package and load per language, so the
|
|
5
|
+
// admin bundle carries only the language in use. Each import becomes its own chunk.
|
|
6
|
+
const catalogs = {
|
|
7
|
+
fr: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/fr.json", { with: { type: "json" } }),
|
|
8
|
+
de: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/de.json", { with: { type: "json" } }),
|
|
9
|
+
nl: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/nl.json", { with: { type: "json" } }),
|
|
10
|
+
es: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/es.json", { with: { type: "json" } }),
|
|
11
|
+
it: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/it.json", { with: { type: "json" } }),
|
|
12
|
+
pt: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/pt.json", { with: { type: "json" } }),
|
|
13
|
+
"pt-BR": () => import("@vermeulen.solutions/eventual-locales/catalogs/core/pt-BR.json", { with: { type: "json" } }),
|
|
14
|
+
pl: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/pl.json", { with: { type: "json" } }),
|
|
15
|
+
cs: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/cs.json", { with: { type: "json" } }),
|
|
16
|
+
sv: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/sv.json", { with: { type: "json" } }),
|
|
17
|
+
da: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/da.json", { with: { type: "json" } }),
|
|
18
|
+
nb: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/nb.json", { with: { type: "json" } }),
|
|
19
|
+
fi: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/fi.json", { with: { type: "json" } }),
|
|
20
|
+
ja: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/ja.json", { with: { type: "json" } }),
|
|
21
|
+
"zh-CN": () => import("@vermeulen.solutions/eventual-locales/catalogs/core/zh-CN.json", { with: { type: "json" } }),
|
|
22
|
+
ko: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/ko.json", { with: { type: "json" } }),
|
|
23
|
+
tr: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/tr.json", { with: { type: "json" } }),
|
|
24
|
+
uk: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/uk.json", { with: { type: "json" } }),
|
|
25
|
+
ar: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/ar.json", { with: { type: "json" } }),
|
|
26
|
+
he: () => import("@vermeulen.solutions/eventual-locales/catalogs/core/he.json", { with: { type: "json" } }),
|
|
27
|
+
};
|
|
28
|
+
const translators = new Map();
|
|
29
|
+
const pending = new Map();
|
|
30
|
+
const listeners = new Set();
|
|
31
|
+
|
|
32
|
+
/** Load the catalog for a UI locale; resolves once editorText can translate into it. */
|
|
33
|
+
export function loadEditorCatalog(locale) {
|
|
34
|
+
const lang = resolveLocale(locale, LOCALES);
|
|
35
|
+
if (lang === "en" || translators.has(lang)) return Promise.resolve();
|
|
36
|
+
if (!pending.has(lang)) {
|
|
37
|
+
pending.set(lang, Promise.resolve(catalogs[lang]?.())
|
|
38
|
+
.then(module => { translators.set(lang, module ? textTranslator(module.default ?? module, lang) : null); })
|
|
39
|
+
.catch(() => { translators.set(lang, null); })
|
|
40
|
+
.then(() => { for (const listener of listeners) listener(); }));
|
|
41
|
+
}
|
|
42
|
+
return pending.get(lang);
|
|
43
|
+
}
|
|
44
|
+
/** Re-render hook point: called after a catalog arrives. Returns an unsubscribe function. */
|
|
45
|
+
export function onEditorCatalog(listener) {
|
|
46
|
+
listeners.add(listener);
|
|
47
|
+
return () => listeners.delete(listener);
|
|
48
|
+
}
|
|
49
|
+
if (typeof document !== "undefined" && document.documentElement?.lang) loadEditorCatalog(document.documentElement.lang);
|
|
50
|
+
|
|
51
|
+
const publishReasons = ["Publish a valid referenced venue before publishing or scheduling this event.", "Publish the referenced organizer before publishing or scheduling this event."];
|
|
52
|
+
export function editorText(value, locale = "en") {
|
|
53
|
+
if (typeof value !== "string") return value;
|
|
54
|
+
const lang = resolveLocale(locale, LOCALES);
|
|
55
|
+
if (lang === "en") return value;
|
|
56
|
+
const translate = translators.get(lang);
|
|
57
|
+
if (translate === undefined) { loadEditorCatalog(lang); return value; }
|
|
58
|
+
if (!translate) return value;
|
|
59
|
+
const translated = translate(value);
|
|
60
|
+
if (translated !== value) return translated;
|
|
61
|
+
// Host errors wrap these reasons in their own sentence; show the actionable part.
|
|
62
|
+
for (const reason of publishReasons) if (value.includes(reason)) return translate(reason);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
const presentationKeys = new Set(["label", "text", "title", "description", "placeholder", "empty_text", "confirm", "deny"]);
|
|
66
|
+
const statuses = { scheduled: "Scheduled", cancelled: "Cancelled", modified: "Rescheduled", rescheduled: "Rescheduled", published: "Published", draft: "Draft", archived: "Archived" };
|
|
67
|
+
// English keeps the stored status word, as before; other languages get the translated label.
|
|
68
|
+
const statusText = (status, locale) => status in statuses && resolveLocale(locale, LOCALES) !== "en" ? editorText(statuses[status], locale) : status;
|
|
69
|
+
// Confirmed English fallbacks in core's 1.0.1 French catalog. Merge through
|
|
70
|
+
// Lingui's public API, preserving already translated or host-customized text.
|
|
71
|
+
const coreFrench = [
|
|
72
|
+
["xVT291","Live version",["Version publiée"]],
|
|
73
|
+
["TNKBrC","Visitors see this published version",["Les visiteurs voient cette version publiée"]],
|
|
74
|
+
["vaizKG","Publication date",["Date de publication"]],
|
|
75
|
+
["GJIQ9P","Created and updated",["Création et modification"]],
|
|
76
|
+
["mWCZbu","URL & language",["Adresse et langue"]],
|
|
77
|
+
["7FCZPo","Content language",["Langue du contenu"]],
|
|
78
|
+
["28x9RX","Choose bylines",["Choisir les collaborateurs"]],
|
|
79
|
+
["57VuPS","Drop an image here or <0>browse</0>",["Déposez une image ici ou <0>parcourez les fichiers</0>"]],
|
|
80
|
+
["jPRo6i",null,["Déposez une image ici ou choisissez un fichier pour ",["label"]]],
|
|
81
|
+
];
|
|
82
|
+
export function fillFrenchCoreMessages(i18n) {
|
|
83
|
+
if(i18n.locale !== "fr") return false;
|
|
84
|
+
const patch={};
|
|
85
|
+
for(const [id,english,translation] of coreFrench) {
|
|
86
|
+
const expected=english===null ? ["Drop an image here or browse for ",["label"]] : [english];
|
|
87
|
+
if(i18n.messages[id]===undefined || JSON.stringify(i18n.messages[id])===JSON.stringify(expected)) patch[id]=translation;
|
|
88
|
+
}
|
|
89
|
+
if(!Object.keys(patch).length) return false;
|
|
90
|
+
i18n.load("fr",patch);return true;
|
|
91
|
+
}
|
|
92
|
+
// Presentation labels only. Unique native IDs identify selections; never copy
|
|
93
|
+
// these labels into the draft patch or change the host's receipt validation.
|
|
94
|
+
const directoryLabels = new Map();
|
|
95
|
+
export function draftSummary(field, source, locale, timezone = "UTC") {
|
|
96
|
+
if (source === null || source === undefined || source === "") return "—";
|
|
97
|
+
let value = source;
|
|
98
|
+
if (["recurrence", "exceptions", "occurrence_content", "categories"].includes(field) && typeof value === "string") {
|
|
99
|
+
try { value = JSON.parse(value); } catch { return editorText("Stored event data needs repair", locale); }
|
|
100
|
+
}
|
|
101
|
+
if (["venue", "venue_id", "organizer_ref", "organizer_id"].includes(field)) return directoryLabels.get(String(value)) ?? String(value);
|
|
102
|
+
if (typeof value === "boolean") return editorText(value ? "Yes" : "No", locale);
|
|
103
|
+
if (field === "recurrence" && value && typeof value === "object") {
|
|
104
|
+
const n=value.interval ?? 1, unit={daily:"days",weekly:"weeks",monthly:"months"}[value.frequency];
|
|
105
|
+
let summary=n===1 ? value.frequency : `every ${n} ${unit}`;
|
|
106
|
+
if (value.frequency === "weekly" && value.weekdays?.length) summary=`every ${n===1 ? "week" : `${n} weeks`} on ` + value.weekdays.map(day=>day[0].toUpperCase()+day.slice(1)).join(", ");
|
|
107
|
+
if (value.frequency === "monthly" && value.pattern) {
|
|
108
|
+
const p=value.pattern;
|
|
109
|
+
summary += p.type === "dayOfMonth" ? ` on day ${p.dayOfMonth} (${p.missingDayBehavior === "skip" ? "skip missing months" : "use last day if missing"})` : ` on ${p.position === "last" ? "last" : ["first","second","third","fourth","fifth"][p.position-1]} ${p.weekday[0].toUpperCase()+p.weekday.slice(1)}`;
|
|
110
|
+
}
|
|
111
|
+
return editorText(summary + " through " + value.until,locale);
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
if (field === "categories") return value.join(", ") || "—";
|
|
115
|
+
if (field === "exceptions" || field === "occurrence_content") return value.length ? value.map(item=>{
|
|
116
|
+
const original=String(item.recurrenceId ?? item.date ?? "");let date=original;
|
|
117
|
+
try {date=new Intl.DateTimeFormat(locale,{dateStyle:"medium",...(original.length===10 ? {} : {timeStyle:"short"}),timeZone:"UTC"}).format(new Date(original.length===10 ? original : original+"Z"));} catch {}
|
|
118
|
+
const overrides=item.overrides ?? {};
|
|
119
|
+
if(field === "exceptions") return date+" — "+(item.status ? statusText(item.status, locale) : editorText("Changed date", locale))+(overrides.start ? " → "+draftSummary("start",overrides.start,locale,overrides.timezone || timezone)+(overrides.end ? " – "+draftSummary("end",overrides.end,locale,overrides.timezone || timezone) : "") : "");
|
|
120
|
+
const plain=value=>typeof value === "string" ? value : Array.isArray(value) ? value.flatMap(block=>block.children?.map(child=>child.text ?? "") ?? []).join(" ") : String(value);
|
|
121
|
+
return date+" — "+Object.entries(overrides).map(([key,value])=>editorText(key[0].toUpperCase()+key.slice(1),locale)+": "+plain(value)).join("; ");
|
|
122
|
+
}).join("; ") : "—";
|
|
123
|
+
}
|
|
124
|
+
if (["start","end","start_date","end_date"].includes(field)) {
|
|
125
|
+
try { return new Intl.DateTimeFormat(locale, {dateStyle:"long",...(String(value).length===10 ? {} : {timeStyle:"short"}),timeZone:String(value).length===10 ? "UTC" : timezone}).format(new Date(String(value))); } catch { return String(value); }
|
|
126
|
+
}
|
|
127
|
+
return typeof value === "string" ? value : String(value);
|
|
128
|
+
}
|
|
129
|
+
export function localizeEventualBlocks(blocks, locale) {
|
|
130
|
+
if (!blocks.some(block => block.block_id === "eventual-ui")) return blocks;
|
|
131
|
+
const walk = (value, parent = "") => {
|
|
132
|
+
if (Array.isArray(value)) return value.flatMap(item => item?.type === "table" && item.rows?.every(row=>row.action?.action_id === "edit-occurrence") ? walk(item,parent) : [walk(item,parent)]);
|
|
133
|
+
if (!value || typeof value !== "object") return value;
|
|
134
|
+
if (value.block_id === "eventual-verbatim") return value;
|
|
135
|
+
if(value.type === "table" && value.rows?.every(row=>row.action?.action_id === "edit-occurrence")) {
|
|
136
|
+
if(!value.rows.length) return [{type:"context",text:editorText(value.empty_text,locale)}];
|
|
137
|
+
return value.rows.flatMap(row=>{
|
|
138
|
+
const id="eventual-date-"+row.action.value;
|
|
139
|
+
const fields=row.date === row.effective ? [{label:editorText("Date",locale),value:row.date}] : [{label:editorText("Original date",locale),value:row.date},{label:editorText("Current date",locale),value:row.effective}];
|
|
140
|
+
if(row.status !== "scheduled") fields.push({label:editorText("Status",locale),value:statusText(row.status, locale)});
|
|
141
|
+
return [{type:"fields",block_id:id,fields},{type:"actions",block_id:id+"-actions",elements:[walk(row.action)]},{type:"divider",block_id:id+"-end"}];
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (["venue","organizer_ref"].includes(value.action_id) && Array.isArray(value.options)) {
|
|
145
|
+
for (const option of value.options) if (option.value) directoryLabels.set(option.value, option.label);
|
|
146
|
+
while (directoryLabels.size > 10000) directoryLabels.delete(directoryLabels.keys().next().value);
|
|
147
|
+
}
|
|
148
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => {
|
|
149
|
+
if (key === "rows") return [key, item.map(row => ({ ...row, status: statusText(row.status, locale), ...Object.fromEntries(Object.entries(row).filter(([, cell]) => cell && typeof cell === "object" && cell.type).map(([column, cell]) => [column, walk(cell)])) }))];
|
|
150
|
+
// Values/options contain stored values; localize only their presentation properties.
|
|
151
|
+
if (presentationKeys.has(key) && typeof item === "string") return [key, editorText(item, locale)];
|
|
152
|
+
if (["initial_value", "value", "target", "condition"].includes(key)) return [key, item];
|
|
153
|
+
return [key, walk(item, key)];
|
|
154
|
+
}));
|
|
155
|
+
};
|
|
156
|
+
return walk(blocks);
|
|
157
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Shared output rules for sandbox feeds and headless consumers. */
|
|
2
|
+
export function safeWebUrl(value: string, base?: string): string {
|
|
3
|
+
if (typeof value !== 'string' || !value.trim()) return "";
|
|
4
|
+
try {
|
|
5
|
+
const url = base ? new URL(value, base) : new URL(value);
|
|
6
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url.href : "";
|
|
7
|
+
} catch {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type EventDetails = { location: string; locationType?: string; virtualUrl?: string; status?: string };
|
|
13
|
+
|
|
14
|
+
export function calendarLocation(event: EventDetails): string {
|
|
15
|
+
const online = safeWebUrl(event.virtualUrl ?? "");
|
|
16
|
+
if (event.locationType === "virtual") return online || event.location;
|
|
17
|
+
if (event.locationType === "hybrid") return [event.location, online].filter(Boolean).join(" · ");
|
|
18
|
+
return event.location;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function calendarEventUrl(event: Pick<EventDetails, "locationType" | "virtualUrl"> & { externalUrl: string }): string {
|
|
22
|
+
return safeWebUrl(event.externalUrl) || (event.locationType === "virtual" || event.locationType === "hybrid" ? safeWebUrl(event.virtualUrl ?? "") : "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function calendarStatus(event: Pick<EventDetails, "status">): string {
|
|
26
|
+
return event.status === "cancelled" ? "CANCELLED" : event.status === "postponed" ? "TENTATIVE" : "CONFIRMED";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { buildCalendarLinks, type CalendarLinks, type CalendarEventInput } from "../src/domain/calendar-links";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PublicEvent } from "./feed";
|
|
2
|
+
import { safeWebUrl } from "./event-details";
|
|
3
|
+
export function civilDate(value: string, timezone: string): string {
|
|
4
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
5
|
+
timeZone: timezone,
|
|
6
|
+
calendar: "gregory",
|
|
7
|
+
numberingSystem: "latn",
|
|
8
|
+
year: "numeric",
|
|
9
|
+
month: "2-digit",
|
|
10
|
+
day: "2-digit",
|
|
11
|
+
}).formatToParts(new Date(value));
|
|
12
|
+
const part = (type: string) =>
|
|
13
|
+
parts.find((item) => item.type === type)?.value ?? "";
|
|
14
|
+
return part("year") + "-" + part("month") + "-" + part("day");
|
|
15
|
+
}
|
|
16
|
+
export function displayEventDate(event: PublicEvent, locale: string): string {
|
|
17
|
+
try {
|
|
18
|
+
return new Intl.DateTimeFormat(locale, {
|
|
19
|
+
timeZone: event.allDay ? "UTC" : event.timezone,
|
|
20
|
+
dateStyle: "long",
|
|
21
|
+
...(event.allDay ? {} : { timeStyle: "short" }),
|
|
22
|
+
}).format(
|
|
23
|
+
new Date(event.allDay ? event.start + "T00:00:00Z" : event.start),
|
|
24
|
+
);
|
|
25
|
+
} catch {
|
|
26
|
+
return event.start;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function eventPageUrl(event: PublicEvent, basePath = "/events"): string {
|
|
30
|
+
const supplied =
|
|
31
|
+
event.publicUrl &&
|
|
32
|
+
(safeWebUrl(event.publicUrl) ||
|
|
33
|
+
(event.publicUrl.startsWith("/") && !event.publicUrl.startsWith("//")
|
|
34
|
+
? event.publicUrl
|
|
35
|
+
: ""));
|
|
36
|
+
const url = new URL(
|
|
37
|
+
supplied ||
|
|
38
|
+
basePath.replace(/\/$/, "") +
|
|
39
|
+
"/" +
|
|
40
|
+
encodeURIComponent(event.slug ?? event.id.split("#")[0]!),
|
|
41
|
+
"https://eventual.invalid",
|
|
42
|
+
);
|
|
43
|
+
try {
|
|
44
|
+
url.searchParams.set(
|
|
45
|
+
"from",
|
|
46
|
+
event.allDay ? event.start : civilDate(event.start, event.timezone),
|
|
47
|
+
);
|
|
48
|
+
url.searchParams.set(
|
|
49
|
+
"through",
|
|
50
|
+
event.allDay ? event.end : civilDate(event.end, event.timezone),
|
|
51
|
+
);
|
|
52
|
+
} catch {}
|
|
53
|
+
return url.origin === "https://eventual.invalid"
|
|
54
|
+
? url.pathname + url.search + url.hash
|
|
55
|
+
: url.href;
|
|
56
|
+
}
|