@sveltia/ui 0.27.9 → 0.28.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.
@@ -8,6 +8,6 @@ type Dialog = {
8
8
  * @see https://w3c.github.io/aria/#dialog
9
9
  * @see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
10
10
  */
11
- declare const Dialog: import("svelte").Component<ModalProps & DialogProps & Record<string, any>, {}, "value" | "open">;
11
+ declare const Dialog: import("svelte").Component<ModalProps & DialogProps & Record<string, any>, {}, "open" | "value">;
12
12
  import type { ModalProps } from '../../typedefs';
13
13
  import type { DialogProps } from '../../typedefs';
@@ -27,7 +27,7 @@ declare const PromptDialog: import("svelte").Component<ModalProps & DialogProps
27
27
  * Input slot content.
28
28
  */
29
29
  input?: Snippet<[]> | undefined;
30
- } & Record<string, any>, {}, "value" | "open">;
30
+ } & Record<string, any>, {}, "open" | "value">;
31
31
  type Props = {
32
32
  /**
33
33
  * Value entered on the textbox.
@@ -83,7 +83,7 @@ declare const Slider: import("svelte").Component<{
83
83
  values?: number[];
84
84
  value?: number;
85
85
  }) => void) | undefined;
86
- } & Record<string, any>, {}, "value" | "values">;
86
+ } & Record<string, any>, {}, "values" | "value">;
87
87
  type Props = {
88
88
  /**
89
89
  * Current value.
@@ -40,7 +40,7 @@
40
40
  let {
41
41
  /* eslint-disable prefer-const */
42
42
  code = $bindable(''),
43
- lang = $bindable(''),
43
+ lang = $bindable('plain'),
44
44
  showLanguageSwitcher = false,
45
45
  flex = false,
46
46
  hidden = false,
@@ -85,7 +85,7 @@
85
85
  void editorStore.inputValue;
86
86
 
87
87
  untrack(() => {
88
- const { lang: _lang = '', code: _code = '' } =
88
+ const { lang: _lang = 'plain', code: _code = '' } =
89
89
  editorStore.inputValue.match(/^```(?<lang>\w+?)?\n(?:(?<code>.*)\n)?```/s)?.groups ?? {};
90
90
 
91
91
  if (lang !== _lang) {
@@ -1,4 +1,4 @@
1
- export function initEditor({ components, isCodeEditor, defaultLanguage }: TextEditorConfig): LexicalEditor;
1
+ export function initEditor({ components, isCodeEditor, defaultLanguage, }: TextEditorConfig): LexicalEditor;
2
2
  export function loadCodeHighlighter(lang: string): Promise<void>;
3
3
  export function convertMarkdownToLexical(editor: LexicalEditor, value: string): Promise<void>;
4
4
  export function focusEditor(editor: LexicalEditor): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  CodeHighlightNode,
3
3
  CodeNode,
4
+ PrismTokenizer,
4
5
  $createCodeNode as createCodeNode,
5
6
  $isCodeHighlightNode as isCodeHighlightNode,
6
7
  $isCodeNode as isCodeNode,
@@ -233,7 +234,11 @@ const onEditorUpdate = (editor) => {
233
234
  * @param {TextEditorConfig} config Editor configuration.
234
235
  * @returns {LexicalEditor} Editor instance.
235
236
  */
236
- export const initEditor = ({ components = [], isCodeEditor = false, defaultLanguage = '' }) => {
237
+ export const initEditor = ({
238
+ components = [],
239
+ isCodeEditor = false,
240
+ defaultLanguage = 'plain',
241
+ }) => {
237
242
  components.forEach(({ node, transformer }) => {
238
243
  /** @type {any[]} */ (editorConfig.nodes).unshift(node);
239
244
  allTransformers.unshift(transformer);
@@ -250,6 +255,7 @@ export const initEditor = ({ components = [], isCodeEditor = false, defaultLangu
250
255
  // eslint-disable-next-line jsdoc/require-jsdoc
251
256
  tokenize: (code, lang = 'plain') =>
252
257
  window.Prism.tokenize(code, window.Prism.languages[lang] ?? window.Prism.languages.plain),
258
+ $tokenize: PrismTokenizer.$tokenize,
253
259
  });
254
260
 
255
261
  editor.registerCommand(
@@ -391,7 +397,7 @@ export const loadCodeHighlighter = async (lang) => {
391
397
  export const convertMarkdownToLexical = async (editor, value) => {
392
398
  // Load Prism language support on demand; the `loadLanguages` Prism utility method cannot be used
393
399
  await Promise.all(
394
- [...value.matchAll(/^```(?<lang>.+?)\n/gm)].map(async ({ groups: { lang } = {} }) =>
400
+ [...value.matchAll(/^```(?<lang>.+?)\n/gm)].map(async ({ groups: { lang = 'plain' } = {} }) =>
395
401
  loadCodeHighlighter(lang),
396
402
  ),
397
403
  );
@@ -46,7 +46,7 @@
46
46
  /** @type {TextEditorStore} */
47
47
  const editorStore = getContext('editorStore');
48
48
 
49
- let selectedLanguage = $state('');
49
+ let selectedLanguage = $state('plain');
50
50
 
51
51
  $effect(() => {
52
52
  void editorStore.selection.blockNodeKey;
@@ -57,7 +57,7 @@
57
57
  : getNodeByKey(/** @type {string} */ (editorStore.selection.blockNodeKey));
58
58
 
59
59
  if (isCodeNode(node)) {
60
- selectedLanguage = node.getLanguage() ?? editorStore.config.defaultLanguage ?? '';
60
+ selectedLanguage = node.getLanguage() ?? editorStore.config.defaultLanguage ?? 'plain';
61
61
  }
62
62
  });
63
63
  });
@@ -89,7 +89,7 @@
89
89
  }
90
90
  }}
91
91
  >
92
- <Option label={$_('_sui.text_editor.plain_text')} value="" />
92
+ <Option label={$_('_sui.text_editor.plain_text')} value="plain" />
93
93
  {#each codeLanguages as { key, label, aliases } (key)}
94
94
  <Option
95
95
  {label}
@@ -20,7 +20,7 @@
20
20
  let {
21
21
  /* eslint-disable prefer-const */
22
22
  code = $bindable(''),
23
- lang = $bindable(''),
23
+ lang = $bindable('plain'),
24
24
  disabled = false,
25
25
  children,
26
26
  ...restProps
@@ -29,6 +29,7 @@
29
29
  /* eslint-disable prefer-const */
30
30
  value = $bindable(),
31
31
  flex = false,
32
+ monospace = true,
32
33
  class: className,
33
34
  hidden = false,
34
35
  disabled = false,
@@ -71,6 +72,7 @@
71
72
  type="password"
72
73
  spellcheck="false"
73
74
  {flex}
75
+ {monospace}
74
76
  {hidden}
75
77
  {disabled}
76
78
  {readonly}
@@ -9,7 +9,6 @@
9
9
  import TruncatedText from '../typography/truncated-text.svelte';
10
10
 
11
11
  /**
12
- * @import { Snippet } from 'svelte';
13
12
  * @import { CommonEventHandlers, InputEventHandlers, TextInputProps } from '../../typedefs';
14
13
  */
15
14
 
@@ -31,6 +30,7 @@
31
30
  showInlineLabel = false,
32
31
  inputmode = 'text',
33
32
  flex = false,
33
+ monospace = false,
34
34
  class: className,
35
35
  hidden = false,
36
36
  disabled = false,
@@ -50,6 +50,7 @@
50
50
  role="none"
51
51
  class="sui text-input {className}"
52
52
  class:flex
53
+ class:monospace
53
54
  class:disabled
54
55
  class:readonly
55
56
  {hidden}
@@ -96,6 +97,9 @@
96
97
  width: stretch;
97
98
  min-width: 0;
98
99
  }
100
+ .text-input.monospace {
101
+ --sui-textbox-font-family: var(--sui-font-family-monospace, monospace);
102
+ }
99
103
 
100
104
  input:is(:-webkit-autofill, :-webkit-autofill:focus) {
101
105
  transition: background-color 0s 600000s, color 0s 600000s;
@@ -13,7 +13,7 @@ declare const TextInput: import("svelte").Component<TextInputProps & import("../
13
13
  * Input value.
14
14
  */
15
15
  value?: string | undefined;
16
- } & Record<string, any>, {}, "value" | "element">;
16
+ } & Record<string, any>, {}, "element" | "value">;
17
17
  type Props = {
18
18
  /**
19
19
  * Input value.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export function initLocales({ fallbackLocale, initialLocale }?: {
2
- fallbackLocale?: string | undefined;
3
- initialLocale?: string | undefined;
4
- } | undefined): void;
5
1
  export { default as Alert } from "./components/alert/alert.svelte";
6
2
  export { default as Infobar } from "./components/alert/infobar.svelte";
7
3
  export { default as BottomNavigation } from "./components/bottom-navigation/bottom-navigation.svelte";
@@ -77,4 +73,6 @@ export { default as AppShell } from "./components/util/app-shell.svelte";
77
73
  export { default as EmptyState } from "./components/util/empty-state.svelte";
78
74
  export { default as Group } from "./components/util/group.svelte";
79
75
  export { default as Modal } from "./components/util/modal.svelte";
76
+ export { initLocales };
80
77
  export * from "./typedefs";
78
+ import { initLocales } from './services/i18n';
package/dist/index.js CHANGED
@@ -1,29 +1,4 @@
1
- import { addMessages, init } from 'svelte-i18n';
2
-
3
- /**
4
- * Load strings and initialize the locales.
5
- * @param {object} [init] Initialize options.
6
- * @param {string} [init.fallbackLocale] Fallback locale.
7
- * @param {string} [init.initialLocale] Initial locale.
8
- * @see https://github.com/kaisermann/svelte-i18n/blob/main/docs/Getting%20Started.md
9
- * @see https://vitejs.dev/guide/features.html#glob-import
10
- */
11
- export const initLocales = ({ fallbackLocale = 'en', initialLocale = 'en' } = {}) => {
12
- /** @type {{ [key: string]: { strings: object }}} */
13
- const modules = import.meta.glob('./locales/*.js', { eager: true });
14
-
15
- Object.entries(modules).forEach(([path, { strings }]) => {
16
- const [, locale] = /** @type {string[]} */ (path.match(/([a-zA-Z-]+)\.js/));
17
-
18
- // Add `_sui` suffix to avoid collision with app localization
19
- addMessages(locale, /** @type {any} */ ({ _sui: strings }));
20
- });
21
-
22
- init({
23
- fallbackLocale,
24
- initialLocale,
25
- });
26
- };
1
+ import { initLocales } from './services/i18n';
27
2
 
28
3
  initLocales();
29
4
 
@@ -102,5 +77,7 @@ export { default as AppShell } from './components/util/app-shell.svelte';
102
77
  export { default as EmptyState } from './components/util/empty-state.svelte';
103
78
  export { default as Group } from './components/util/group.svelte';
104
79
  export { default as Modal } from './components/util/modal.svelte';
80
+ export { initLocales };
105
81
 
106
- // eslint-disable-next-line import/export export * from './typedefs';
82
+ // eslint-disable-next-line import/export
83
+ export * from './typedefs';
@@ -0,0 +1,4 @@
1
+ export function initLocales({ fallbackLocale, initialLocale }?: {
2
+ fallbackLocale?: string | undefined;
3
+ initialLocale?: string | undefined;
4
+ } | undefined): void;
@@ -0,0 +1,47 @@
1
+ import { addMessages, locale as appLocale, init } from 'svelte-i18n';
2
+
3
+ /**
4
+ * Load strings and initialize the locales.
5
+ * @param {object} [init] Initialize options.
6
+ * @param {string} [init.fallbackLocale] Fallback locale.
7
+ * @param {string} [init.initialLocale] Initial locale.
8
+ * @see https://github.com/kaisermann/svelte-i18n/blob/main/docs/Getting%20Started.md
9
+ * @see https://vitejs.dev/guide/features.html#glob-import
10
+ */
11
+ export const initLocales = ({ fallbackLocale = 'en', initialLocale = 'en' } = {}) => {
12
+ /** @type {{ [key: string]: { strings: object }}} */
13
+ const modules = import.meta.glob('../locales/*.js', { eager: true });
14
+
15
+ Object.entries(modules).forEach(([path, { strings }]) => {
16
+ const [, locale] = /** @type {string[]} */ (path.match(/([a-zA-Z-]+)\.js/));
17
+
18
+ // Add `_sui` suffix to avoid collision with app localization
19
+ addMessages(locale, /** @type {any} */ ({ _sui: strings }));
20
+ });
21
+
22
+ init({
23
+ fallbackLocale,
24
+ initialLocale,
25
+ });
26
+ };
27
+
28
+ /**
29
+ * List of RTL locales: Arabic, Persian, Hebrew, Urdu.
30
+ */
31
+ const RTL_LOCALES = ['ar', 'fa', 'he', 'ur'];
32
+
33
+ /**
34
+ * Get the text direction of the given locale.
35
+ * @param {string | null | undefined} locale Locale code.
36
+ * @returns {'rtl' | 'ltr'} Text direction.
37
+ */
38
+ const getDirection = (locale) =>
39
+ locale && RTL_LOCALES.includes(locale.split('-')[0]) ? 'rtl' : 'ltr';
40
+
41
+ if (!import.meta.env.SSR) {
42
+ // Set the `dir` attribute on the HTML element based on the current locale.
43
+ // @todo Move this to Sveltia UI and then Sveltia I18N
44
+ appLocale.subscribe((value) => {
45
+ document.documentElement.dir = getDirection(value);
46
+ });
47
+ }
@@ -444,6 +444,10 @@ export type TextInputProps = {
444
444
  * Make the text input container flexible.
445
445
  */
446
446
  flex?: boolean | undefined;
447
+ /**
448
+ * Whether to use a monospace font for the input text.
449
+ */
450
+ monospace?: boolean | undefined;
447
451
  /**
448
452
  * The `class` attribute on the wrapper element.
449
453
  */
package/dist/typedefs.js CHANGED
@@ -158,6 +158,7 @@
158
158
  * @property {'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'} [inputmode] The
159
159
  * `inputmode` attribute on the `<input>`.
160
160
  * @property {boolean} [flex] Make the text input container flexible.
161
+ * @property {boolean} [monospace] Whether to use a monospace font for the input text.
161
162
  * @property {string} [class] The `class` attribute on the wrapper element.
162
163
  * @property {boolean} [hidden] Whether to hide the widget.
163
164
  * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.27.9",
3
+ "version": "0.28.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -29,49 +29,49 @@
29
29
  "test:watch": "vitest"
30
30
  },
31
31
  "dependencies": {
32
- "@lexical/code": "^0.33.1",
33
- "@lexical/dragon": "^0.33.1",
34
- "@lexical/history": "^0.33.1",
35
- "@lexical/link": "^0.33.1",
36
- "@lexical/list": "^0.33.1",
37
- "@lexical/markdown": "^0.33.1",
38
- "@lexical/rich-text": "^0.33.1",
39
- "@lexical/selection": "^0.33.1",
40
- "@lexical/table": "^0.33.1",
41
- "@lexical/utils": "^0.33.1",
32
+ "@lexical/code": "^0.35.0",
33
+ "@lexical/dragon": "^0.35.0",
34
+ "@lexical/history": "^0.35.0",
35
+ "@lexical/link": "^0.35.0",
36
+ "@lexical/list": "^0.35.0",
37
+ "@lexical/markdown": "^0.35.0",
38
+ "@lexical/rich-text": "^0.35.0",
39
+ "@lexical/selection": "^0.35.0",
40
+ "@lexical/table": "^0.35.0",
41
+ "@lexical/utils": "^0.35.0",
42
42
  "@sveltia/utils": "^0.8.0",
43
- "lexical": "^0.33.1",
44
- "prismjs": "^1.30.0"
43
+ "lexical": "^0.35.0",
44
+ "prismjs": "^1.30.0",
45
+ "svelte-i18n": "^4.0.1"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "svelte": "^5.0.0"
48
49
  },
49
50
  "devDependencies": {
50
- "@sveltejs/adapter-auto": "^6.0.1",
51
- "@sveltejs/kit": "^2.27.0",
52
- "@sveltejs/package": "^2.4.0",
53
- "@sveltejs/vite-plugin-svelte": "6.1.0",
54
- "cspell": "^9.2.0",
51
+ "@sveltejs/adapter-auto": "^6.1.0",
52
+ "@sveltejs/kit": "^2.39.1",
53
+ "@sveltejs/package": "^2.5.1",
54
+ "@sveltejs/vite-plugin-svelte": "6.2.0",
55
+ "cspell": "^9.2.1",
55
56
  "eslint": "^8.57.1",
56
57
  "eslint-config-airbnb-base": "^15.0.0",
57
58
  "eslint-config-prettier": "^10.1.8",
58
59
  "eslint-plugin-import": "^2.32.0",
59
- "eslint-plugin-jsdoc": "^52.0.2",
60
+ "eslint-plugin-jsdoc": "^57.0.7",
60
61
  "eslint-plugin-svelte": "^2.46.1",
61
62
  "postcss": "^8.5.6",
62
63
  "postcss-html": "^1.8.0",
63
64
  "prettier": "^3.6.2",
64
65
  "prettier-plugin-svelte": "^3.4.0",
65
- "sass": "^1.89.2",
66
- "stylelint": "^16.23.0",
67
- "stylelint-config-recommended-scss": "^15.0.1",
66
+ "sass": "^1.92.1",
67
+ "stylelint": "^16.24.0",
68
+ "stylelint-config-recommended-scss": "^16.0.1",
68
69
  "stylelint-scss": "^6.12.1",
69
- "svelte": "5.37.3",
70
+ "svelte": "5.38.10",
70
71
  "svelte-check": "^4.3.1",
71
- "svelte-i18n": "^4.0.1",
72
72
  "svelte-preprocess": "^6.0.3",
73
73
  "tslib": "^2.8.1",
74
- "vite": "^7.0.6",
74
+ "vite": "^7.1.5",
75
75
  "vitest": "^3.2.4"
76
76
  },
77
77
  "exports": {