@widgetic/creator 0.3.81 → 0.4.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.
Files changed (64) hide show
  1. package/README.md +157 -0
  2. package/dist/CreatorApp.svelte +1593 -812
  3. package/dist/CreatorApp.svelte.d.ts +22 -0
  4. package/dist/components/BrandKitPanel.svelte +48 -40
  5. package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
  6. package/dist/components/DesignQuickEdit.svelte +13 -4
  7. package/dist/components/EditableName.svelte +13 -8
  8. package/dist/components/EditableName.svelte.d.ts +2 -2
  9. package/dist/components/FileUrlSourceControl.svelte +21 -8
  10. package/dist/components/HoverTooltip.svelte +1 -1
  11. package/dist/components/SelectorDropdown.svelte +19 -15
  12. package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
  13. package/dist/components/VersionDropdownRow.svelte +14 -11
  14. package/dist/components/WidgetDetails.svelte +118 -92
  15. package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
  16. package/dist/creator-types.d.ts +96 -0
  17. package/dist/host/creatorHost.d.ts +176 -0
  18. package/dist/host/creatorHost.js +242 -0
  19. package/dist/host/limitRefusal.d.ts +64 -0
  20. package/dist/host/limitRefusal.js +109 -0
  21. package/dist/i18n/index.d.ts +5 -0
  22. package/dist/i18n/index.js +5 -0
  23. package/dist/i18n/labels.d.ts +14 -0
  24. package/dist/i18n/labels.js +39 -0
  25. package/dist/i18n/language.d.ts +559 -0
  26. package/dist/i18n/language.js +47 -0
  27. package/dist/i18n/languageKit.d.ts +52 -0
  28. package/dist/i18n/languageKit.js +45 -0
  29. package/dist/i18n/messages.d.ts +526 -0
  30. package/dist/i18n/messages.js +548 -0
  31. package/dist/i18n/slots.d.ts +22 -0
  32. package/dist/i18n/slots.js +42 -0
  33. package/dist/i18n/statusText.d.ts +22 -0
  34. package/dist/i18n/statusText.js +223 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/stores/userSession.d.ts +8 -1
  38. package/dist/stores/userSession.js +18 -25
  39. package/dist/stores/websocketStore.d.ts +6 -0
  40. package/dist/stores/websocketStore.js +39 -4
  41. package/dist/utils/designIntentTelemetry.d.ts +8 -0
  42. package/dist/utils/designIntentTelemetry.js +52 -34
  43. package/dist/utils/directionPlacement.d.ts +51 -0
  44. package/dist/utils/directionPlacement.js +55 -0
  45. package/dist/utils/embedCode.d.ts +0 -1
  46. package/dist/utils/embedCode.js +0 -4
  47. package/dist/utils/generationSharing.d.ts +122 -0
  48. package/dist/utils/generationSharing.js +188 -0
  49. package/dist/utils/nativeScrollbarPadding.js +1 -1
  50. package/dist/utils/pickedFile.d.ts +15 -0
  51. package/dist/utils/pickedFile.js +21 -0
  52. package/dist/utils/widgeticChatUpload.d.ts +9 -0
  53. package/dist/utils/widgeticChatUpload.js +24 -2
  54. package/package.json +5 -3
  55. package/dist/retiredSurface.test.d.ts +0 -1
  56. package/dist/retiredSurface.test.js +0 -113
  57. package/dist/utils/designIntentResolver.test.d.ts +0 -1
  58. package/dist/utils/designIntentResolver.test.js +0 -246
  59. package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
  60. package/dist/utils/designIntentTelemetry.test.js +0 -385
  61. package/dist/utils/designQuickEditValues.test.d.ts +0 -1
  62. package/dist/utils/designQuickEditValues.test.js +0 -100
  63. package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
  64. package/dist/utils/widgeticChatUpload.test.js +0 -257
@@ -0,0 +1,47 @@
1
+ import { CANVAS_MESSAGES } from '@widgetic/canvas/i18n';
2
+ import { CHAT_MESSAGES } from '@widgetic/chat';
3
+ import { ALL_EDITOR_MESSAGES } from '@widgetic/editor';
4
+ import { CREATOR_MESSAGES } from './messages.js';
5
+ import { createCreatorLanguageKit } from './languageKit.js';
6
+ /**
7
+ * The language of a creator on a page. The creator has three packages inside it that draw words of their own (the editor,
8
+ * with the File Browser and the rich text editor in it, the chat and the canvas), each with its own catalog; a page gives
9
+ * ONE flat `messages` object and the creator hands each part the keys that are its own. See `languageKit.ts` for how, and
10
+ * for what a test can swap.
11
+ *
12
+ * The canvas catalog comes from `@widgetic/canvas/i18n`, a light entry: the canvas itself (a very large component and a
13
+ * drawing library) is loaded when it is needed, and must not come along with the words.
14
+ */
15
+ /** The catalogs of the creator and of the packages inside it. A key belongs to one of them. */
16
+ export const CREATOR_CATALOGS = {
17
+ creator: CREATOR_MESSAGES,
18
+ editor: ALL_EDITOR_MESSAGES,
19
+ chat: CHAT_MESSAGES,
20
+ canvas: CANVAS_MESSAGES
21
+ };
22
+ const creatorLanguageKit = createCreatorLanguageKit({ catalogs: CREATOR_CATALOGS });
23
+ /** Every message of the creator and of the packages inside it, as one catalog: what a page's `messages` may have a key of. */
24
+ export const ALL_CREATOR_MESSAGES = creatorLanguageKit.allMessages;
25
+ /**
26
+ * Checks a page's `messages` against all the creator's catalogs without showing anything: a key that does not exist (with
27
+ * the nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
28
+ * is never given. An empty list means every message will be used. For a test or a build step of the page.
29
+ */
30
+ export const checkCreatorMessages = creatorLanguageKit.checkMessages;
31
+ /** Gives each part the entries of the page's `messages` that are its own (the creator, the editor, the chat, the canvas). */
32
+ export const splitCreatorMessages = creatorLanguageKit.splitMessages;
33
+ /**
34
+ * Called by the root component of a creator while it is created, so everything inside it speaks the page's language.
35
+ * The context belongs to one root component, so two creators on a page can speak two languages.
36
+ */
37
+ export const provideCreatorLanguage = creatorLanguageKit.provideLanguage;
38
+ /**
39
+ * Called by a part of the creator while it is created. Gives its words as stores, so a part that is already on the screen
40
+ * changes when the page sets the language again. Outside a creator (a control used on its own) it speaks English.
41
+ */
42
+ export const useCreatorLanguage = creatorLanguageKit.useLanguage;
43
+ /**
44
+ * The English `t` of the creator, for code that has no component around it. The screens of the creator get their words, in
45
+ * the page's language, from `useCreatorLanguage`.
46
+ */
47
+ export const translateEnglish = creatorLanguageKit.translateEnglish;
@@ -0,0 +1,52 @@
1
+ import { type I18nContext, type I18nHandle, type I18nSettings, type MessageOverrides, type MessageProblem, type SvelteContextApi, type Translate } from '@widgetic/design-system/i18n';
2
+ import type { CreatorMessageKey } from './messages.js';
3
+ /**
4
+ * The language of a creator on a page.
5
+ *
6
+ * The creator has three packages inside it that draw words of their own: the editor (with the File Browser and the rich
7
+ * text editor inside it), the chat and the canvas, and each speaks from its own catalog. A page does not have to know
8
+ * that: it gives ONE flat `messages` object, and this hands each part the keys that are its own.
9
+ *
10
+ * It is made from the catalogs, in a function, so a test can make one from catalogs of its own and with stand-ins for
11
+ * Svelte's context (the packages inside the creator are Svelte components, which a test in Node cannot load). The creator
12
+ * makes the one it uses in `language.ts`.
13
+ */
14
+ /** The catalogs of the creator and of the packages inside it. A key belongs to one of them. */
15
+ export interface CreatorCatalogs {
16
+ creator: Readonly<Record<CreatorMessageKey, string>>;
17
+ /** Everything the editor draws: its own words, the File Browser's and the rich text editor's (the editor splits them again). */
18
+ editor: Readonly<Record<string, string>>;
19
+ chat: Readonly<Record<string, string>>;
20
+ canvas: Readonly<Record<string, string>>;
21
+ }
22
+ /** What one flat `messages` object becomes: for each part, the entries that are its own. */
23
+ export type CreatorMessageSlices = Record<keyof CreatorCatalogs, MessageOverrides>;
24
+ export interface CreatorLanguageKitOptions {
25
+ catalogs: CreatorCatalogs;
26
+ /** Stand-ins for Svelte's `getContext` and `setContext`; tests only. */
27
+ contextApi?: SvelteContextApi;
28
+ /** Where the warnings go; tests only. */
29
+ logger?: Pick<Console, 'warn'>;
30
+ }
31
+ export interface CreatorLanguageKit {
32
+ /** Every message of the creator and of the packages inside it, as one catalog: what a page's `messages` may have a key of. */
33
+ allMessages: Readonly<Record<string, string>>;
34
+ /**
35
+ * Checks a page's `messages` against all the creator's catalogs without showing anything: a key that does not exist
36
+ * (with the nearest real one), a value that is not text, a template that does not parse, or one that asks for a value
37
+ * the message is never given. An empty list means every message will be used. For a test or a build step of the page.
38
+ */
39
+ checkMessages(messages: MessageOverrides): MessageProblem[];
40
+ /**
41
+ * Gives each part the entries of the page's `messages` that are its own. A key no catalog has (a misspelt one) is
42
+ * said once in the console, and nobody is given it.
43
+ */
44
+ splitMessages(messages: MessageOverrides | null | undefined): CreatorMessageSlices;
45
+ /** Called by the root component of a creator while it is created, so everything inside it speaks the page's language. */
46
+ provideLanguage(initial: I18nSettings): I18nHandle<CreatorMessageKey>;
47
+ /** Called by a part of the creator while it is created. Outside a creator it speaks English. */
48
+ useLanguage(): I18nContext<CreatorMessageKey>;
49
+ /** The English `t` of the creator, for code that has no component around it. */
50
+ translateEnglish: Translate<CreatorMessageKey>;
51
+ }
52
+ export declare function createCreatorLanguageKit(options: CreatorLanguageKitOptions): CreatorLanguageKit;
@@ -0,0 +1,45 @@
1
+ import { createI18n, describeMessageProblem, findMessageProblems, splitMessages } from '@widgetic/design-system/i18n';
2
+ /** How many different problems the console is told about, so a page that keeps changing its messages cannot fill memory. */
3
+ const MAX_REPORTED_KEYS = 200;
4
+ export function createCreatorLanguageKit(options) {
5
+ const { catalogs } = options;
6
+ const logger = options.logger ?? console;
7
+ const allMessages = {
8
+ ...catalogs.canvas,
9
+ ...catalogs.chat,
10
+ ...catalogs.editor,
11
+ ...catalogs.creator
12
+ };
13
+ // The creator's own translator hears only the creator's keys: a key of the chat is not "unknown" to it.
14
+ const creatorWords = createI18n({
15
+ catalog: catalogs.creator,
16
+ label: 'Creator',
17
+ contextApi: options.contextApi
18
+ });
19
+ const reportedKeys = new Set();
20
+ /** Says a key of the page's `messages` that no catalog has, once per page however often the language is set. */
21
+ function reportUnclaimedKeys(unclaimed) {
22
+ if (Object.keys(unclaimed).length === 0)
23
+ return;
24
+ for (const problem of findMessageProblems(allMessages, unclaimed)) {
25
+ const text = describeMessageProblem(problem);
26
+ if (reportedKeys.has(text) || reportedKeys.size >= MAX_REPORTED_KEYS)
27
+ continue;
28
+ reportedKeys.add(text);
29
+ logger.warn(`[Creator] ${text}`);
30
+ }
31
+ }
32
+ function split(messages) {
33
+ const { slices, unclaimed } = splitMessages(messages, catalogs);
34
+ reportUnclaimedKeys(unclaimed);
35
+ return slices;
36
+ }
37
+ return {
38
+ allMessages,
39
+ checkMessages: (messages) => findMessageProblems(allMessages, messages),
40
+ splitMessages: split,
41
+ provideLanguage: creatorWords.provideI18n,
42
+ useLanguage: creatorWords.useI18n,
43
+ translateEnglish: creatorWords.translateEnglish
44
+ };
45
+ }