@tutti-os/ui-rich-text 0.0.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.
@@ -0,0 +1,268 @@
1
+ import {
2
+ createRichTextLinkMarkdown,
3
+ createRichTextMentionMarkdown
4
+ } from "./chunk-52PIIFZA.js";
5
+
6
+ // src/plugins/mention.ts
7
+ var richTextMentionTrigger = "@";
8
+ function normalizeOptionalString(value) {
9
+ const trimmed = value?.trim();
10
+ return trimmed ? trimmed : void 0;
11
+ }
12
+ function normalizeMentionMeta(meta) {
13
+ if (!meta) {
14
+ return void 0;
15
+ }
16
+ const nextEntries = Object.entries(meta).map(([key, value]) => [key.trim(), value.trim()]).filter(([key, value]) => key.length > 0 && value.length > 0);
17
+ if (nextEntries.length === 0) {
18
+ return void 0;
19
+ }
20
+ return Object.freeze(Object.fromEntries(nextEntries));
21
+ }
22
+ function createRichTextMentionAttrs(pluginId, mention) {
23
+ const plugin = pluginId.trim();
24
+ const entityId = mention.entityId.trim();
25
+ const label = mention.label.trim();
26
+ if (!plugin) {
27
+ throw new Error("Rich text mention plugin id is required.");
28
+ }
29
+ if (!entityId) {
30
+ throw new Error("Rich text mention entityId is required.");
31
+ }
32
+ if (!label) {
33
+ throw new Error("Rich text mention label is required.");
34
+ }
35
+ return {
36
+ trigger: richTextMentionTrigger,
37
+ plugin,
38
+ entityId,
39
+ label,
40
+ href: normalizeOptionalString(mention.href),
41
+ kind: normalizeOptionalString(mention.kind),
42
+ version: normalizeOptionalString(mention.version),
43
+ meta: normalizeMentionMeta(mention.meta)
44
+ };
45
+ }
46
+ function isRichTextMentionAttrs(value) {
47
+ if (!value || typeof value !== "object") {
48
+ return false;
49
+ }
50
+ const candidate = value;
51
+ return candidate.trigger === richTextMentionTrigger && typeof candidate.plugin === "string" && candidate.plugin.trim().length > 0 && typeof candidate.entityId === "string" && candidate.entityId.trim().length > 0 && typeof candidate.label === "string" && candidate.label.trim().length > 0;
52
+ }
53
+ function getRichTextMentionDisplayText(attrs) {
54
+ return `@${attrs.label}`;
55
+ }
56
+ function resolveRichTextMentionView(mention, resolved) {
57
+ const state = resolved?.state ?? "active";
58
+ const label = resolved?.label?.trim() || mention.label;
59
+ const href = normalizeOptionalString(resolved?.href);
60
+ const tooltip = normalizeOptionalString(resolved?.tooltip);
61
+ return {
62
+ state,
63
+ label,
64
+ tooltip,
65
+ href,
66
+ entity: resolved?.entity,
67
+ interactive: state === "active"
68
+ };
69
+ }
70
+ function createRichTextMentionPlugin(plugin) {
71
+ const id = plugin.id.trim();
72
+ if (!id) {
73
+ throw new Error("Rich text mention plugin id is required.");
74
+ }
75
+ return {
76
+ ...plugin,
77
+ id,
78
+ trigger: richTextMentionTrigger
79
+ };
80
+ }
81
+
82
+ // src/plugins/at.ts
83
+ var richTextAtTrigger = "@";
84
+ function normalizeRequiredString(value, fieldName) {
85
+ const trimmed = value.trim();
86
+ if (!trimmed) {
87
+ throw new Error(`Rich text ${fieldName} is required.`);
88
+ }
89
+ return trimmed;
90
+ }
91
+ function createRichTextTextInsertResult(text) {
92
+ return {
93
+ kind: "text",
94
+ text
95
+ };
96
+ }
97
+ function createRichTextMarkdownLinkInsertResult(label, href) {
98
+ return {
99
+ kind: "markdown-link",
100
+ label: normalizeRequiredString(label, "insert label"),
101
+ href: normalizeRequiredString(href, "insert href")
102
+ };
103
+ }
104
+ function createRichTextMentionInsertResult(mention) {
105
+ return {
106
+ kind: "mention",
107
+ mention
108
+ };
109
+ }
110
+ function renderRichTextAtInsertResult(providerId, result) {
111
+ switch (result.kind) {
112
+ case "mention":
113
+ return createRichTextMentionMarkdown(
114
+ createRichTextMentionAttrs(providerId, result.mention)
115
+ );
116
+ case "markdown-link":
117
+ return createRichTextLinkMarkdown({
118
+ name: result.label,
119
+ path: result.href,
120
+ kind: result.href.endsWith("/") ? "folder" : "file"
121
+ });
122
+ case "text":
123
+ return result.text;
124
+ default:
125
+ return "";
126
+ }
127
+ }
128
+ function createRichTextAtProvider(provider) {
129
+ const id = normalizeRequiredString(provider.id, "provider id");
130
+ return {
131
+ ...provider,
132
+ id,
133
+ trigger: richTextAtTrigger
134
+ };
135
+ }
136
+
137
+ // src/plugins/atRegistry.ts
138
+ function normalizeProviderId(providerId) {
139
+ return providerId.trim();
140
+ }
141
+ function createRichTextAtRegistry(providers) {
142
+ const providerMap = /* @__PURE__ */ new Map();
143
+ for (const provider of providers) {
144
+ const providerId = normalizeProviderId(provider.id);
145
+ if (!providerId) {
146
+ throw new Error("Rich text @ provider id is required.");
147
+ }
148
+ if (providerMap.has(providerId)) {
149
+ throw new Error(`Duplicate rich text @ provider id: ${providerId}`);
150
+ }
151
+ providerMap.set(providerId, provider);
152
+ }
153
+ async function query(input) {
154
+ if (input.abortSignal?.aborted) {
155
+ return [];
156
+ }
157
+ const matches = await Promise.all(
158
+ [...providerMap.values()].map(async (provider) => {
159
+ if (input.abortSignal?.aborted) {
160
+ return [];
161
+ }
162
+ const items = await provider.query(input);
163
+ if (input.abortSignal?.aborted) {
164
+ return [];
165
+ }
166
+ return items.map((item) => ({
167
+ providerId: provider.id,
168
+ key: provider.getItemKey(item),
169
+ label: provider.getItemLabel(item),
170
+ subtitle: provider.getItemSubtitle?.(item) || void 0,
171
+ keywords: provider.getItemKeywords?.(item),
172
+ item,
173
+ insertResult: provider.toInsertResult(item)
174
+ }));
175
+ })
176
+ );
177
+ const flatMatches = matches.flat();
178
+ const limit = input.maxResults;
179
+ if (typeof limit === "number" && limit >= 0) {
180
+ return flatMatches.slice(0, limit);
181
+ }
182
+ return flatMatches;
183
+ }
184
+ return {
185
+ listProviders: () => [...providerMap.values()],
186
+ getProvider: (providerId) => providerMap.get(normalizeProviderId(providerId)),
187
+ query
188
+ };
189
+ }
190
+
191
+ // src/plugins/mentionRegistry.ts
192
+ function normalizePluginId(pluginId) {
193
+ return pluginId.trim();
194
+ }
195
+ function createRichTextMentionRegistry(plugins) {
196
+ const pluginMap = /* @__PURE__ */ new Map();
197
+ for (const plugin of plugins) {
198
+ const pluginId = normalizePluginId(plugin.id);
199
+ if (!pluginId) {
200
+ throw new Error("Rich text mention plugin id is required.");
201
+ }
202
+ if (pluginMap.has(pluginId)) {
203
+ throw new Error(`Duplicate rich text mention plugin id: ${pluginId}`);
204
+ }
205
+ pluginMap.set(pluginId, plugin);
206
+ }
207
+ async function query(input) {
208
+ const matches = await Promise.all(
209
+ [...pluginMap.values()].map(async (plugin) => {
210
+ const items = await plugin.query(input);
211
+ return items.map((item) => ({
212
+ pluginId: plugin.id,
213
+ key: plugin.getItemKey(item),
214
+ label: plugin.getItemLabel(item),
215
+ subtitle: plugin.getItemSubtitle?.(item) || void 0,
216
+ keywords: plugin.getItemKeywords?.(item),
217
+ item,
218
+ mention: createRichTextMentionAttrs(plugin.id, plugin.toMention(item))
219
+ }));
220
+ })
221
+ );
222
+ const flatMatches = matches.flat();
223
+ const limit = input.maxResults;
224
+ if (typeof limit === "number" && limit >= 0) {
225
+ return flatMatches.slice(0, limit);
226
+ }
227
+ return flatMatches;
228
+ }
229
+ async function resolve(input) {
230
+ const plugin = pluginMap.get(input.mention.plugin);
231
+ if (!plugin) {
232
+ return resolveRichTextMentionView(input.mention, {
233
+ state: "missing"
234
+ });
235
+ }
236
+ if (!plugin.resolveMention) {
237
+ return resolveRichTextMentionView(input.mention, {
238
+ state: "active"
239
+ });
240
+ }
241
+ return resolveRichTextMentionView(
242
+ input.mention,
243
+ await plugin.resolveMention(input)
244
+ );
245
+ }
246
+ return {
247
+ listPlugins: () => [...pluginMap.values()],
248
+ getPlugin: (pluginId) => pluginMap.get(normalizePluginId(pluginId)),
249
+ query,
250
+ resolve
251
+ };
252
+ }
253
+
254
+ export {
255
+ createRichTextMentionAttrs,
256
+ isRichTextMentionAttrs,
257
+ getRichTextMentionDisplayText,
258
+ resolveRichTextMentionView,
259
+ createRichTextMentionPlugin,
260
+ createRichTextTextInsertResult,
261
+ createRichTextMarkdownLinkInsertResult,
262
+ createRichTextMentionInsertResult,
263
+ renderRichTextAtInsertResult,
264
+ createRichTextAtProvider,
265
+ createRichTextAtRegistry,
266
+ createRichTextMentionRegistry
267
+ };
268
+ //# sourceMappingURL=chunk-K5POY2YJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugins/mention.ts","../src/plugins/at.ts","../src/plugins/atRegistry.ts","../src/plugins/mentionRegistry.ts"],"sourcesContent":["import type {\n RichTextMentionAttrs,\n RichTextMentionInsert,\n RichTextMentionPlugin,\n RichTextResolvedMention,\n RichTextResolvedMentionView\n} from \"../types/mention.ts\";\n\nconst richTextMentionTrigger = \"@\";\n\nfunction normalizeOptionalString(value?: string | null): string | undefined {\n const trimmed = value?.trim();\n return trimmed ? trimmed : undefined;\n}\n\nfunction normalizeMentionMeta(\n meta?: Readonly<Record<string, string>> | null\n): Readonly<Record<string, string>> | undefined {\n if (!meta) {\n return undefined;\n }\n\n const nextEntries = Object.entries(meta)\n .map(([key, value]) => [key.trim(), value.trim()] as const)\n .filter(([key, value]) => key.length > 0 && value.length > 0);\n\n if (nextEntries.length === 0) {\n return undefined;\n }\n\n return Object.freeze(Object.fromEntries(nextEntries));\n}\n\nexport function createRichTextMentionAttrs(\n pluginId: string,\n mention: RichTextMentionInsert\n): RichTextMentionAttrs {\n const plugin = pluginId.trim();\n const entityId = mention.entityId.trim();\n const label = mention.label.trim();\n\n if (!plugin) {\n throw new Error(\"Rich text mention plugin id is required.\");\n }\n if (!entityId) {\n throw new Error(\"Rich text mention entityId is required.\");\n }\n if (!label) {\n throw new Error(\"Rich text mention label is required.\");\n }\n\n return {\n trigger: richTextMentionTrigger,\n plugin,\n entityId,\n label,\n href: normalizeOptionalString(mention.href),\n kind: normalizeOptionalString(mention.kind),\n version: normalizeOptionalString(mention.version),\n meta: normalizeMentionMeta(mention.meta)\n };\n}\n\nexport function isRichTextMentionAttrs(\n value: unknown\n): value is RichTextMentionAttrs {\n if (!value || typeof value !== \"object\") {\n return false;\n }\n\n const candidate = value as Partial<RichTextMentionAttrs>;\n return (\n candidate.trigger === richTextMentionTrigger &&\n typeof candidate.plugin === \"string\" &&\n candidate.plugin.trim().length > 0 &&\n typeof candidate.entityId === \"string\" &&\n candidate.entityId.trim().length > 0 &&\n typeof candidate.label === \"string\" &&\n candidate.label.trim().length > 0\n );\n}\n\nexport function getRichTextMentionDisplayText(\n attrs: RichTextMentionAttrs\n): string {\n return `@${attrs.label}`;\n}\n\nexport function resolveRichTextMentionView(\n mention: RichTextMentionAttrs,\n resolved?: RichTextResolvedMention | null\n): RichTextResolvedMentionView {\n const state = resolved?.state ?? \"active\";\n const label = resolved?.label?.trim() || mention.label;\n const href = normalizeOptionalString(resolved?.href);\n const tooltip = normalizeOptionalString(resolved?.tooltip);\n\n return {\n state,\n label,\n tooltip,\n href,\n entity: resolved?.entity,\n interactive: state === \"active\"\n };\n}\n\nexport function createRichTextMentionPlugin<TItem, TResolved = unknown>(\n plugin: RichTextMentionPlugin<TItem, TResolved>\n): RichTextMentionPlugin<TItem, TResolved> {\n const id = plugin.id.trim();\n if (!id) {\n throw new Error(\"Rich text mention plugin id is required.\");\n }\n\n return {\n ...plugin,\n id,\n trigger: richTextMentionTrigger\n };\n}\n","import { createRichTextMentionAttrs } from \"./mention.ts\";\nimport {\n createRichTextMentionMarkdown,\n createRichTextLinkMarkdown\n} from \"../core/richTextDocument.ts\";\nimport type {\n RichTextAtInsertResult,\n RichTextAtProvider,\n RichTextMarkdownLinkInsertResult,\n RichTextMentionAtInsertResult,\n RichTextTextInsertResult\n} from \"../types/at.ts\";\n\nconst richTextAtTrigger = \"@\";\n\nfunction normalizeRequiredString(value: string, fieldName: string): string {\n const trimmed = value.trim();\n if (!trimmed) {\n throw new Error(`Rich text ${fieldName} is required.`);\n }\n return trimmed;\n}\n\nexport function createRichTextTextInsertResult(\n text: string\n): RichTextTextInsertResult {\n return {\n kind: \"text\",\n text\n };\n}\n\nexport function createRichTextMarkdownLinkInsertResult(\n label: string,\n href: string\n): RichTextMarkdownLinkInsertResult {\n return {\n kind: \"markdown-link\",\n label: normalizeRequiredString(label, \"insert label\"),\n href: normalizeRequiredString(href, \"insert href\")\n };\n}\n\nexport function createRichTextMentionInsertResult(\n mention: RichTextMentionAtInsertResult[\"mention\"]\n): RichTextMentionAtInsertResult {\n return {\n kind: \"mention\",\n mention\n };\n}\n\nexport function renderRichTextAtInsertResult(\n providerId: string,\n result: RichTextAtInsertResult\n): string {\n switch (result.kind) {\n case \"mention\":\n return createRichTextMentionMarkdown(\n createRichTextMentionAttrs(providerId, result.mention)\n );\n case \"markdown-link\":\n return createRichTextLinkMarkdown({\n name: result.label,\n path: result.href,\n kind: result.href.endsWith(\"/\") ? \"folder\" : \"file\"\n });\n case \"text\":\n return result.text;\n default:\n return \"\";\n }\n}\n\nexport function createRichTextAtProvider<TItem>(\n provider: RichTextAtProvider<TItem>\n): RichTextAtProvider<TItem> {\n const id = normalizeRequiredString(provider.id, \"provider id\");\n\n return {\n ...provider,\n id,\n trigger: richTextAtTrigger\n };\n}\n","import type {\n RichTextAtProvider,\n RichTextAtQueryInput,\n RichTextAtQueryMatch,\n RichTextAtRegistry\n} from \"../types/at.ts\";\n\nfunction normalizeProviderId(providerId: string): string {\n return providerId.trim();\n}\n\nexport function createRichTextAtRegistry(\n providers: readonly RichTextAtProvider[]\n): RichTextAtRegistry {\n const providerMap = new Map<string, RichTextAtProvider>();\n\n for (const provider of providers) {\n const providerId = normalizeProviderId(provider.id);\n if (!providerId) {\n throw new Error(\"Rich text @ provider id is required.\");\n }\n if (providerMap.has(providerId)) {\n throw new Error(`Duplicate rich text @ provider id: ${providerId}`);\n }\n providerMap.set(providerId, provider);\n }\n\n async function query(\n input: RichTextAtQueryInput\n ): Promise<readonly RichTextAtQueryMatch[]> {\n if (input.abortSignal?.aborted) {\n return [];\n }\n\n const matches = await Promise.all(\n [...providerMap.values()].map(async (provider) => {\n if (input.abortSignal?.aborted) {\n return [];\n }\n const items = await provider.query(input);\n if (input.abortSignal?.aborted) {\n return [];\n }\n return items.map<RichTextAtQueryMatch>((item) => ({\n providerId: provider.id,\n key: provider.getItemKey(item),\n label: provider.getItemLabel(item),\n subtitle: provider.getItemSubtitle?.(item) || undefined,\n keywords: provider.getItemKeywords?.(item),\n item,\n insertResult: provider.toInsertResult(item)\n }));\n })\n );\n\n const flatMatches = matches.flat();\n const limit = input.maxResults;\n if (typeof limit === \"number\" && limit >= 0) {\n return flatMatches.slice(0, limit);\n }\n return flatMatches;\n }\n\n return {\n listProviders: () => [...providerMap.values()],\n getProvider: (providerId: string) =>\n providerMap.get(normalizeProviderId(providerId)),\n query\n };\n}\n","import {\n createRichTextMentionAttrs,\n resolveRichTextMentionView\n} from \"./mention.ts\";\nimport type {\n RichTextMentionPlugin,\n RichTextMentionQueryInput,\n RichTextMentionQueryMatch,\n RichTextMentionRegistry,\n RichTextMentionResolveInput,\n RichTextResolvedMentionView\n} from \"../types/mention.ts\";\n\nfunction normalizePluginId(pluginId: string): string {\n return pluginId.trim();\n}\n\nexport function createRichTextMentionRegistry(\n plugins: readonly RichTextMentionPlugin[]\n): RichTextMentionRegistry {\n const pluginMap = new Map<string, RichTextMentionPlugin>();\n\n for (const plugin of plugins) {\n const pluginId = normalizePluginId(plugin.id);\n if (!pluginId) {\n throw new Error(\"Rich text mention plugin id is required.\");\n }\n if (pluginMap.has(pluginId)) {\n throw new Error(`Duplicate rich text mention plugin id: ${pluginId}`);\n }\n pluginMap.set(pluginId, plugin);\n }\n\n async function query(\n input: RichTextMentionQueryInput\n ): Promise<readonly RichTextMentionQueryMatch[]> {\n const matches = await Promise.all(\n [...pluginMap.values()].map(async (plugin) => {\n const items = await plugin.query(input);\n return items.map<RichTextMentionQueryMatch>((item) => ({\n pluginId: plugin.id,\n key: plugin.getItemKey(item),\n label: plugin.getItemLabel(item),\n subtitle: plugin.getItemSubtitle?.(item) || undefined,\n keywords: plugin.getItemKeywords?.(item),\n item,\n mention: createRichTextMentionAttrs(plugin.id, plugin.toMention(item))\n }));\n })\n );\n\n const flatMatches = matches.flat();\n const limit = input.maxResults;\n if (typeof limit === \"number\" && limit >= 0) {\n return flatMatches.slice(0, limit);\n }\n return flatMatches;\n }\n\n async function resolve(\n input: RichTextMentionResolveInput\n ): Promise<RichTextResolvedMentionView> {\n const plugin = pluginMap.get(input.mention.plugin);\n if (!plugin) {\n return resolveRichTextMentionView(input.mention, {\n state: \"missing\"\n });\n }\n\n if (!plugin.resolveMention) {\n return resolveRichTextMentionView(input.mention, {\n state: \"active\"\n });\n }\n\n return resolveRichTextMentionView(\n input.mention,\n await plugin.resolveMention(input)\n );\n }\n\n return {\n listPlugins: () => [...pluginMap.values()],\n getPlugin: (pluginId: string) => pluginMap.get(normalizePluginId(pluginId)),\n query,\n resolve\n };\n}\n"],"mappings":";;;;;;AAQA,IAAM,yBAAyB;AAE/B,SAAS,wBAAwB,OAA2C;AAC1E,QAAM,UAAU,OAAO,KAAK;AAC5B,SAAO,UAAU,UAAU;AAC7B;AAEA,SAAS,qBACP,MAC8C;AAC9C,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,OAAO,QAAQ,IAAI,EACpC,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,IAAI,KAAK,GAAG,MAAM,KAAK,CAAC,CAAU,EACzD,OAAO,CAAC,CAAC,KAAK,KAAK,MAAM,IAAI,SAAS,KAAK,MAAM,SAAS,CAAC;AAE9D,MAAI,YAAY,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,OAAO,OAAO,YAAY,WAAW,CAAC;AACtD;AAEO,SAAS,2BACd,UACA,SACsB;AACtB,QAAM,SAAS,SAAS,KAAK;AAC7B,QAAM,WAAW,QAAQ,SAAS,KAAK;AACvC,QAAM,QAAQ,QAAQ,MAAM,KAAK;AAEjC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AACA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA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H;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM,OAAO,eAAe,KAAK;AAAA,IACnC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,aAAa,MAAM,CAAC,GAAG,UAAU,OAAO,CAAC;AAAA,IACzC,WAAW,CAAC,aAAqB,UAAU,IAAI,kBAAkB,QAAQ,CAAC;AAAA,IAC1E;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,63 @@
1
+ // src/i18n/richTextI18n.ts
2
+ import {
3
+ createI18nRuntime,
4
+ createScopedI18nRuntime,
5
+ createScopedLocaleObjectsI18nModuleManifest
6
+ } from "@tutti-os/ui-i18n-runtime";
7
+ var richTextI18nNamespace = "richText";
8
+ var richTextI18nModule = createScopedLocaleObjectsI18nModuleManifest({
9
+ localeObjectByLocale: {
10
+ en: "richTextEn",
11
+ "zh-CN": "richTextZhCN"
12
+ },
13
+ name: "ui-rich-text",
14
+ namespace: richTextI18nNamespace,
15
+ sourceRoot: "packages/ui/rich-text/src"
16
+ });
17
+ var richTextEn = {
18
+ richTextAt: {
19
+ loading: "Loading...",
20
+ noMatches: "No matches",
21
+ removeReferenceActionLabel: "Remove reference"
22
+ }
23
+ };
24
+ var richTextZhCN = {
25
+ richTextAt: {
26
+ loading: "\u6B63\u5728\u52A0\u8F7D...",
27
+ noMatches: "\u6CA1\u6709\u5339\u914D\u9879",
28
+ removeReferenceActionLabel: "\u79FB\u9664\u5F15\u7528"
29
+ }
30
+ };
31
+ var richTextDefaults = {
32
+ en: richTextEn,
33
+ "zh-CN": richTextZhCN
34
+ };
35
+ var richTextI18nResources = {
36
+ en: {
37
+ [richTextI18nNamespace]: richTextDefaults.en
38
+ },
39
+ "zh-CN": {
40
+ [richTextI18nNamespace]: richTextDefaults["zh-CN"]
41
+ }
42
+ };
43
+ var defaultRichTextI18n = createI18nRuntime({
44
+ dictionaries: [richTextI18nResources.en]
45
+ });
46
+ function createRichTextI18nRuntime(runtime) {
47
+ return createScopedI18nRuntime(
48
+ runtime ?? defaultRichTextI18n,
49
+ richTextI18nNamespace
50
+ );
51
+ }
52
+ function createDefaultRichTextI18nRuntime() {
53
+ return createRichTextI18nRuntime();
54
+ }
55
+
56
+ export {
57
+ richTextI18nNamespace,
58
+ richTextI18nModule,
59
+ richTextI18nResources,
60
+ createRichTextI18nRuntime,
61
+ createDefaultRichTextI18nRuntime
62
+ };
63
+ //# sourceMappingURL=chunk-VQHCWUBH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/i18n/richTextI18n.ts"],"sourcesContent":["import {\n createI18nRuntime,\n createScopedI18nRuntime,\n createScopedLocaleObjectsI18nModuleManifest,\n type I18nDictionary,\n type I18nRuntime\n} from \"@tutti-os/ui-i18n-runtime\";\n\ntype RichTextI18nLocale = \"en\" | \"zh-CN\";\n\nexport const richTextI18nNamespace = \"richText\";\nexport const richTextI18nModule = createScopedLocaleObjectsI18nModuleManifest({\n localeObjectByLocale: {\n en: \"richTextEn\",\n \"zh-CN\": \"richTextZhCN\"\n },\n name: \"ui-rich-text\",\n namespace: richTextI18nNamespace,\n sourceRoot: \"packages/ui/rich-text/src\"\n});\n\nconst richTextEn = {\n richTextAt: {\n loading: \"Loading...\",\n noMatches: \"No matches\",\n removeReferenceActionLabel: \"Remove reference\"\n }\n} as const satisfies I18nDictionary;\n\nconst richTextZhCN = {\n richTextAt: {\n loading: \"正在加载...\",\n noMatches: \"没有匹配项\",\n removeReferenceActionLabel: \"移除引用\"\n }\n} as const satisfies I18nDictionary;\n\nexport type RichTextI18nKey =\n | \"richTextAt.loading\"\n | \"richTextAt.noMatches\"\n | \"richTextAt.removeReferenceActionLabel\";\n\nexport type RichTextI18nRuntime = I18nRuntime<RichTextI18nKey>;\n\nconst richTextDefaults: Record<RichTextI18nLocale, I18nDictionary> = {\n en: richTextEn,\n \"zh-CN\": richTextZhCN\n};\n\nexport const richTextI18nResources: Record<RichTextI18nLocale, I18nDictionary> =\n {\n en: {\n [richTextI18nNamespace]: richTextDefaults.en\n },\n \"zh-CN\": {\n [richTextI18nNamespace]: richTextDefaults[\"zh-CN\"]\n }\n };\n\nconst defaultRichTextI18n = createI18nRuntime({\n dictionaries: [richTextI18nResources.en]\n});\n\nexport function createRichTextI18nRuntime(\n runtime?: I18nRuntime<string>\n): RichTextI18nRuntime {\n return createScopedI18nRuntime<RichTextI18nKey>(\n runtime ?? defaultRichTextI18n,\n richTextI18nNamespace\n );\n}\n\nexport function createDefaultRichTextI18nRuntime(): RichTextI18nRuntime {\n return createRichTextI18nRuntime();\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAIA,IAAM,wBAAwB;AAC9B,IAAM,qBAAqB,4CAA4C;AAAA,EAC5E,sBAAsB;AAAA,IACpB,IAAI;AAAA,IACJ,SAAS;AAAA,EACX;AAAA,EACA,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AACd,CAAC;AAED,IAAM,aAAa;AAAA,EACjB,YAAY;AAAA,IACV,SAAS;AAAA,IACT,WAAW;AAAA,IACX,4BAA4B;AAAA,EAC9B;AACF;AAEA,IAAM,eAAe;AAAA,EACnB,YAAY;AAAA,IACV,SAAS;AAAA,IACT,WAAW;AAAA,IACX,4BAA4B;AAAA,EAC9B;AACF;AASA,IAAM,mBAA+D;AAAA,EACnE,IAAI;AAAA,EACJ,SAAS;AACX;AAEO,IAAM,wBACX;AAAA,EACE,IAAI;AAAA,IACF,CAAC,qBAAqB,GAAG,iBAAiB;AAAA,EAC5C;AAAA,EACA,SAAS;AAAA,IACP,CAAC,qBAAqB,GAAG,iBAAiB,OAAO;AAAA,EACnD;AACF;AAEF,IAAM,sBAAsB,kBAAkB;AAAA,EAC5C,cAAc,CAAC,sBAAsB,EAAE;AACzC,CAAC;AAEM,SAAS,0BACd,SACqB;AACrB,SAAO;AAAA,IACL,WAAW;AAAA,IACX;AAAA,EACF;AACF;AAEO,SAAS,mCAAwD;AACtE,SAAO,0BAA0B;AACnC;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YLWTSNTT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,34 @@
1
+ import { JSONContent } from '@tiptap/core';
2
+ import { R as RichTextMentionAttrs } from '../mention-QICvf4wE.js';
3
+
4
+ type RichTextLinkRef = {
5
+ name: string;
6
+ path: string;
7
+ href: string;
8
+ kind: "file" | "folder";
9
+ };
10
+ type RichTextLinkInput = {
11
+ name?: string | null;
12
+ path: string;
13
+ kind?: "file" | "folder";
14
+ };
15
+ type RichTextMentionRef = RichTextMentionAttrs;
16
+ type RichTextDocument = JSONContent;
17
+ declare function normalizeRichTextContent(value?: string | null): string;
18
+ declare function isRichTextMentionHref(href: string): boolean;
19
+ declare function createRichTextMentionHref(mention: RichTextMentionAttrs): string;
20
+ declare function createRichTextMentionMarkdown(mention: RichTextMentionAttrs): string;
21
+ declare function parseRichTextMentionHref(href: string, label?: string | null): RichTextMentionRef | null;
22
+ declare function normalizeRichTextLinkHref(pathOrHref: string, kind?: "file" | "folder"): string;
23
+ declare function createRichTextLinkMarkdown(input: RichTextLinkInput): string;
24
+ declare function appendRichTextLinksToContent(value: string | null | undefined, refs: readonly RichTextLinkInput[]): string;
25
+ declare function extractRichTextLinksFromContent(value: string | null | undefined): RichTextLinkRef[];
26
+ declare function extractRichTextMentionsFromContent(value: string | null | undefined): RichTextMentionRef[];
27
+ declare function removeRichTextMentionFromContent(content: string, mention: Pick<RichTextMentionAttrs, "plugin" | "entityId">): string;
28
+ declare function removeRichTextLinkFromContent(content: string, path: string): string;
29
+ declare function extractPlainTextFromContent(value?: string | null): string;
30
+ declare function extractPlainTextWithoutFilesFromContent(value?: string | null): string;
31
+ declare function parseRichTextContentToDocument(value?: string | null): RichTextDocument;
32
+ declare function serializeRichTextDocumentToContent(document: RichTextDocument): string;
33
+
34
+ export { type RichTextDocument, type RichTextLinkInput, type RichTextLinkRef, type RichTextMentionRef, appendRichTextLinksToContent, createRichTextLinkMarkdown, createRichTextMentionHref, createRichTextMentionMarkdown, extractPlainTextFromContent, extractPlainTextWithoutFilesFromContent, extractRichTextLinksFromContent, extractRichTextMentionsFromContent, isRichTextMentionHref, normalizeRichTextContent, normalizeRichTextLinkHref, parseRichTextContentToDocument, parseRichTextMentionHref, removeRichTextLinkFromContent, removeRichTextMentionFromContent, serializeRichTextDocumentToContent };
@@ -0,0 +1,38 @@
1
+ import "../chunk-YLWTSNTT.js";
2
+ import {
3
+ appendRichTextLinksToContent,
4
+ createRichTextLinkMarkdown,
5
+ createRichTextMentionHref,
6
+ createRichTextMentionMarkdown,
7
+ extractPlainTextFromContent,
8
+ extractPlainTextWithoutFilesFromContent,
9
+ extractRichTextLinksFromContent,
10
+ extractRichTextMentionsFromContent,
11
+ isRichTextMentionHref,
12
+ normalizeRichTextContent,
13
+ normalizeRichTextLinkHref,
14
+ parseRichTextContentToDocument,
15
+ parseRichTextMentionHref,
16
+ removeRichTextLinkFromContent,
17
+ removeRichTextMentionFromContent,
18
+ serializeRichTextDocumentToContent
19
+ } from "../chunk-52PIIFZA.js";
20
+ export {
21
+ appendRichTextLinksToContent,
22
+ createRichTextLinkMarkdown,
23
+ createRichTextMentionHref,
24
+ createRichTextMentionMarkdown,
25
+ extractPlainTextFromContent,
26
+ extractPlainTextWithoutFilesFromContent,
27
+ extractRichTextLinksFromContent,
28
+ extractRichTextMentionsFromContent,
29
+ isRichTextMentionHref,
30
+ normalizeRichTextContent,
31
+ normalizeRichTextLinkHref,
32
+ parseRichTextContentToDocument,
33
+ parseRichTextMentionHref,
34
+ removeRichTextLinkFromContent,
35
+ removeRichTextMentionFromContent,
36
+ serializeRichTextDocumentToContent
37
+ };
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,77 @@
1
+ import { ReactNode, JSX } from 'react';
2
+ import { RichTextAtProvider } from '../types/index.js';
3
+ import { a as RichTextI18nRuntime } from '../richTextI18n-CUeqHuEQ.js';
4
+ import { R as RichTextMentionAttrs, i as RichTextResolvedMention, j as RichTextResolvedMentionView } from '../mention-QICvf4wE.js';
5
+ import '@tutti-os/ui-i18n-runtime';
6
+
7
+ interface RichTextAtTextOverrides {
8
+ loadingLabel?: string;
9
+ noMatchesLabel?: string;
10
+ removeReferenceActionLabel?: string;
11
+ }
12
+
13
+ interface RichTextAtEditorProps {
14
+ value: string;
15
+ onChange: (value: string) => void;
16
+ providers?: readonly RichTextAtProvider[];
17
+ placeholder?: string;
18
+ disabled?: boolean;
19
+ className?: string;
20
+ textareaClassName?: string;
21
+ placeholderClassName?: string;
22
+ minQueryLength?: number;
23
+ maxResults?: number;
24
+ removeDecorationAriaLabel?: string;
25
+ i18n?: RichTextI18nRuntime;
26
+ textOverrides?: RichTextAtTextOverrides;
27
+ overlay?: ReactNode;
28
+ focusSignal?: unknown;
29
+ }
30
+ declare function RichTextAtEditor({ value, onChange, providers, placeholder, disabled, className, textareaClassName, placeholderClassName, minQueryLength, maxResults, removeDecorationAriaLabel, i18n, textOverrides, overlay, focusSignal }: RichTextAtEditorProps): JSX.Element;
31
+
32
+ interface RichTextAtTextareaProps {
33
+ value: string;
34
+ onChange: (value: string) => void;
35
+ providers?: readonly RichTextAtProvider[];
36
+ placeholder?: string;
37
+ disabled?: boolean;
38
+ className?: string;
39
+ textareaClassName?: string;
40
+ rows?: number;
41
+ minQueryLength?: number;
42
+ maxResults?: number;
43
+ removeDecorationAriaLabel?: string;
44
+ i18n?: RichTextI18nRuntime;
45
+ textOverrides?: RichTextAtTextOverrides;
46
+ overlay?: ReactNode;
47
+ }
48
+ declare function RichTextAtTextarea({ value, onChange, providers, placeholder, disabled, className, textareaClassName, rows, minQueryLength, maxResults, removeDecorationAriaLabel, i18n, textOverrides, overlay }: RichTextAtTextareaProps): JSX.Element;
49
+
50
+ interface RichTextMentionReadonlyClickPayload<TResolved = unknown> {
51
+ mention: RichTextMentionAttrs;
52
+ resolved: RichTextResolvedMentionView<TResolved>;
53
+ }
54
+ interface RichTextMentionReadonlyProps<TResolved = unknown> {
55
+ mention: RichTextMentionAttrs;
56
+ resolved?: RichTextResolvedMention<TResolved> | null;
57
+ className?: string;
58
+ title?: string;
59
+ onClick?: (payload: RichTextMentionReadonlyClickPayload<TResolved>) => void;
60
+ renderLabel?: (payload: RichTextMentionReadonlyClickPayload<TResolved>) => ReactNode;
61
+ }
62
+ declare function RichTextMentionReadonly<TResolved = unknown>({ mention, resolved, className, title, onClick, renderLabel }: RichTextMentionReadonlyProps<TResolved>): JSX.Element;
63
+
64
+ interface RichTextReadonlyWorkspaceReference {
65
+ kind: "file" | "folder";
66
+ label: string;
67
+ path: string;
68
+ }
69
+ interface RichTextReadonlyContentProps {
70
+ value: string;
71
+ className?: string;
72
+ paragraphClassName?: string;
73
+ onOpenWorkspaceReference?: (reference: RichTextReadonlyWorkspaceReference) => void | Promise<void>;
74
+ }
75
+ declare function RichTextReadonlyContent({ value, className, paragraphClassName, onOpenWorkspaceReference }: RichTextReadonlyContentProps): JSX.Element | null;
76
+
77
+ export { RichTextAtEditor, type RichTextAtEditorProps, type RichTextAtTextOverrides, RichTextAtTextarea, type RichTextAtTextareaProps, RichTextMentionReadonly, type RichTextMentionReadonlyClickPayload, type RichTextMentionReadonlyProps, RichTextReadonlyContent, type RichTextReadonlyContentProps, type RichTextReadonlyWorkspaceReference };