@webx-ui/module-settings 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 webx-ui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @webx-ui/module-settings
2
+
3
+ The site's settings, as a section of a [WebX UI](https://github.com/webx-ui/webx-ui) admin
4
+ panel. The screen itself is described by the server — `webx-ui/module-settings` ships the tree
5
+ and the project patches it — and this package draws it and saves it.
6
+
7
+ Nothing here works without the Composer half.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @webx-ui/module-settings
13
+ ```
14
+
15
+ ```ts
16
+ import { createAdmin } from '@webx-ui/module-admin'
17
+ import { settings } from '@webx-ui/module-settings'
18
+ import '@webx-ui/module-settings/style.css'
19
+
20
+ createAdmin({
21
+ modules: [settings()],
22
+ // The project's own operations over the screen, on top of the server's.
23
+ screens: {
24
+ 'settings.index': [{ op: 'set', target: 'project-name', props: { placeholder: 'Acme' } }],
25
+ },
26
+ })
27
+ ```
28
+
29
+ The section appears under "System" in the navigation once the server reports the module.
30
+
31
+ ## What it does
32
+
33
+ - `settings()` — the module: a route at `/settings` and the page.
34
+ - `WxSettingsPage` — the page: loads the values, draws `settings.index` through `WxScreen`, and
35
+ saves with one button. A 422 lands under the field it names.
36
+ - `createSettingsApi(admin)` — `load()` and `save(values)`, for anything else that needs them.
37
+
38
+ The guide: https://webx-ui.github.io/webx-ui/guide/settings.html.
39
+
40
+ ## Licence
41
+
42
+ MIT.
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, HTMLDivElement>;
2
+ export default _default;
package/dist/api.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { AdminContext } from '@webx-ui/module-admin';
2
+ import { SettingsValues } from './types';
3
+ export interface SettingsApi {
4
+ /** Every value the screen describes, as stored. */
5
+ load(): Promise<SettingsValues>;
6
+ /** Sends the values back; answers with what the server kept. A 422 lands as `HttpError`. */
7
+ save(values: SettingsValues): Promise<SettingsValues>;
8
+ }
9
+ /** `GET` and `PUT` on `/settings`, under the panel's API path. */
10
+ export declare function createSettingsApi(admin: AdminContext): SettingsApi;
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** Puts this package's English under the panel's dictionary, once per panel. */
2
+ export declare function useSettingsMessages(): void;
@@ -0,0 +1,5 @@
1
+ export { settings, type SettingsOptions } from './module';
2
+ export { createSettingsApi, type SettingsApi } from './api';
3
+ export { settingsMessages } from './messages';
4
+ export { default as WxSettingsPage } from './SettingsPage';
5
+ export type { SettingsValues } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ import { defineComponent as k, ref as l, computed as V, onMounted as W, openBlock as c, createElementBlock as C, createElementVNode as B, createVNode as M, unref as i, withCtx as m, createTextVNode as y, toDisplayString as _, createBlock as v, createCommentVNode as N } from "vue";
2
+ import { useAdmin as x, useTranslate as P, WxScreen as A } from "@webx-ui/module-admin";
3
+ import { toast as d, WxHeading as E, WxButton as T, WxSkeleton as D } from "@webx-ui/core";
4
+ function H(e) {
5
+ const t = `${e.apiPath}/settings`;
6
+ return {
7
+ async load() {
8
+ return (await e.http.get(t)).data.values;
9
+ },
10
+ async save(s) {
11
+ return (await e.http.put(t, { values: s })).data.values;
12
+ }
13
+ };
14
+ }
15
+ const I = {
16
+ module: {
17
+ title: "Settings"
18
+ },
19
+ page: {
20
+ save: "Save",
21
+ saved: "Settings saved.",
22
+ failed: "Some values were not accepted. Check the highlighted fields."
23
+ }
24
+ }, h = /* @__PURE__ */ new WeakSet();
25
+ function O() {
26
+ try {
27
+ const { i18n: e } = x();
28
+ h.has(e) || (e.defaults("webx-settings", I), h.add(e));
29
+ } catch {
30
+ }
31
+ }
32
+ const U = { class: "wx-settings" }, $ = { class: "wx-settings__head" }, j = /* @__PURE__ */ k({
33
+ __name: "SettingsPage",
34
+ setup(e) {
35
+ const t = x(), s = H(t);
36
+ O();
37
+ const a = P("webx-settings"), o = l({}), u = l({}), p = l(!0), g = l(!1), f = t.can("settings.manage"), b = V(
38
+ () => t.state.manifest?.modules.find((r) => r.id === "settings")?.title ?? a("module.title")
39
+ );
40
+ W(async () => {
41
+ try {
42
+ o.value = await s.load();
43
+ } catch (r) {
44
+ const n = r.body;
45
+ d.danger(n?.message ?? String(r));
46
+ } finally {
47
+ p.value = !1;
48
+ }
49
+ });
50
+ async function S() {
51
+ g.value = !0, u.value = {};
52
+ try {
53
+ o.value = await s.save(o.value), d.success(a("page.saved"));
54
+ } catch (r) {
55
+ const n = r.body;
56
+ n?.errors ? (u.value = n.errors, d.danger(a("page.failed"))) : d.danger(n?.message ?? a("page.failed"));
57
+ } finally {
58
+ g.value = !1;
59
+ }
60
+ }
61
+ return (r, n) => (c(), C("div", U, [
62
+ B("div", $, [
63
+ M(i(E), { level: 2 }, {
64
+ default: m(() => [
65
+ y(_(b.value), 1)
66
+ ]),
67
+ _: 1
68
+ }),
69
+ i(f) ? (c(), v(i(T), {
70
+ key: 0,
71
+ type: "primary",
72
+ loading: g.value,
73
+ onClick: S
74
+ }, {
75
+ default: m(() => [
76
+ y(_(i(a)("page.save")), 1)
77
+ ]),
78
+ _: 1
79
+ }, 8, ["loading"])) : N("", !0)
80
+ ]),
81
+ p.value ? (c(), v(i(D), {
82
+ key: 0,
83
+ rows: 4
84
+ })) : (c(), v(i(A), {
85
+ key: 1,
86
+ modelValue: o.value,
87
+ "onUpdate:modelValue": n[0] || (n[0] = (w) => o.value = w),
88
+ name: "settings.index",
89
+ errors: u.value,
90
+ disabled: !i(f)
91
+ }, null, 8, ["modelValue", "errors", "disabled"]))
92
+ ]));
93
+ }
94
+ }), q = (e, t) => {
95
+ const s = e.__vccOpts || e;
96
+ for (const [a, o] of t)
97
+ s[a] = o;
98
+ return s;
99
+ }, z = /* @__PURE__ */ q(j, [["__scopeId", "data-v-7b2af3ae"]]);
100
+ function K(e = {}) {
101
+ const t = e.path ?? "/settings";
102
+ return {
103
+ id: "settings",
104
+ path: t,
105
+ routes: [{ path: t, name: "webx.settings", component: z }]
106
+ };
107
+ }
108
+ export {
109
+ z as WxSettingsPage,
110
+ H as createSettingsApi,
111
+ K as settings,
112
+ I as settingsMessages
113
+ };
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/api.ts","../src/messages.ts","../src/i18n.ts","../src/SettingsPage.vue","../src/module.ts"],"sourcesContent":["import type { AdminContext } from '@webx-ui/module-admin'\nimport type { SettingsValues } from './types'\n\nexport interface SettingsApi {\n /** Every value the screen describes, as stored. */\n load(): Promise<SettingsValues>\n /** Sends the values back; answers with what the server kept. A 422 lands as `HttpError`. */\n save(values: SettingsValues): Promise<SettingsValues>\n}\n\n/** `GET` and `PUT` on `/settings`, under the panel's API path. */\nexport function createSettingsApi(admin: AdminContext): SettingsApi {\n const base = `${admin.apiPath}/settings`\n\n return {\n async load() {\n const body = await admin.http.get<{ data: { values: SettingsValues } }>(base)\n\n return body.data.values\n },\n async save(values) {\n const body = await admin.http.put<{ data: { values: SettingsValues } }>(base, { values })\n\n return body.data.values\n },\n }\n}\n","import type { Messages } from '@webx-ui/module-admin'\n\n/**\n * What this package says, in English — the same keys `webx-ui/module-settings` ships as\n * `lang/en/*.php`, so a key never reaches the screen when a translation is missing.\n */\nexport const settingsMessages: Record<string, Messages> = {\n module: {\n title: 'Settings',\n },\n page: {\n save: 'Save',\n saved: 'Settings saved.',\n failed: 'Some values were not accepted. Check the highlighted fields.',\n },\n}\n","import { useAdmin } from '@webx-ui/module-admin'\nimport { settingsMessages } from './messages'\n\nconst seeded = new WeakSet<object>()\n\n/** Puts this package's English under the panel's dictionary, once per panel. */\nexport function useSettingsMessages(): void {\n try {\n const { i18n } = useAdmin()\n\n if (!seeded.has(i18n)) {\n i18n.defaults('webx-settings', settingsMessages)\n seeded.add(i18n)\n }\n } catch {\n // Outside a panel there is no dictionary to seed, and `useTranslate` falls back on its own.\n }\n}\n","<script setup lang=\"ts\">\nimport { computed, onMounted, ref } from 'vue'\nimport { useAdmin, useTranslate, WxScreen } from '@webx-ui/module-admin'\nimport { toast, WxButton, WxHeading, WxSkeleton } from '@webx-ui/core'\nimport type { ScreenModel } from '@webx-ui/schema'\nimport { createSettingsApi } from './api'\nimport { useSettingsMessages } from './i18n'\n\n/**\n * The settings section: the screen the server describes, and the one button that is the\n * page's own. The screen does not know how it is saved; this does.\n */\nconst context = useAdmin()\nconst api = createSettingsApi(context)\nuseSettingsMessages()\n\nconst t = useTranslate('webx-settings')\n\nconst values = ref<ScreenModel>({})\nconst errors = ref<Record<string, string[]>>({})\nconst loading = ref(true)\nconst saving = ref(false)\n\nconst canManage = context.can('settings.manage')\n\n/** The section's name, as the server translated it; the built-in English until it arrives. */\nconst title = computed(\n () =>\n context.state.manifest?.modules.find((module) => module.id === 'settings')?.title ??\n t('module.title'),\n)\n\nonMounted(async () => {\n try {\n values.value = await api.load()\n } catch (error) {\n const body = (error as { body?: { message?: string } }).body\n toast.danger(body?.message ?? String(error))\n } finally {\n loading.value = false\n }\n})\n\nasync function save(): Promise<void> {\n saving.value = true\n errors.value = {}\n\n try {\n values.value = await api.save(values.value)\n toast.success(t('page.saved'))\n } catch (error) {\n const body = (error as { body?: { errors?: Record<string, string[]>; message?: string } }).body\n\n if (body?.errors) {\n errors.value = body.errors\n toast.danger(t('page.failed'))\n } else {\n toast.danger(body?.message ?? t('page.failed'))\n }\n } finally {\n saving.value = false\n }\n}\n</script>\n\n<template>\n <div class=\"wx-settings\">\n <div class=\"wx-settings__head\">\n <wx-heading :level=\"2\">{{ title }}</wx-heading>\n <wx-button v-if=\"canManage\" type=\"primary\" :loading=\"saving\" @click=\"save\">\n {{ t('page.save') }}\n </wx-button>\n </div>\n\n <wx-skeleton v-if=\"loading\" :rows=\"4\" />\n <wx-screen\n v-else\n v-model=\"values\"\n name=\"settings.index\"\n :errors=\"errors\"\n :disabled=\"!canManage\"\n />\n </div>\n</template>\n\n<style scoped>\n.wx-settings {\n display: flex;\n flex-direction: column;\n gap: var(--wx-space-16);\n}\n\n.wx-settings__head {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--wx-space-12);\n}\n</style>\n","import type { AdminModule } from '@webx-ui/module-admin'\nimport SettingsPage from './SettingsPage.vue'\n\nexport interface SettingsOptions {\n /** Where the section lives inside the panel. */\n path?: string\n}\n\n/**\n * The settings, as a section of the panel.\n *\n * The id matches the module the server reports, which is what makes the entry appear in the\n * navigation: a section shows up when both halves are installed.\n */\nexport function settings(options: SettingsOptions = {}): AdminModule {\n const path = options.path ?? '/settings'\n\n return {\n id: 'settings',\n path,\n routes: [{ path, name: 'webx.settings', component: SettingsPage }],\n }\n}\n"],"names":["createSettingsApi","admin","base","values","settingsMessages","seeded","useSettingsMessages","i18n","useAdmin","context","api","t","useTranslate","ref","errors","loading","saving","canManage","title","computed","module","onMounted","error","body","toast","save","_openBlock","_createElementBlock","_hoisted_1","_createElementVNode","_hoisted_2","_createVNode","_unref","WxHeading","_createBlock","WxButton","WxSkeleton","WxScreen","$event","settings","options","path","SettingsPage"],"mappings":";;;AAWO,SAASA,EAAkBC,GAAkC;AAClE,QAAMC,IAAO,GAAGD,EAAM,OAAO;AAE7B,SAAO;AAAA,IACL,MAAM,OAAO;AAGX,cAFa,MAAMA,EAAM,KAAK,IAA0CC,CAAI,GAEhE,KAAK;AAAA,IACnB;AAAA,IACA,MAAM,KAAKC,GAAQ;AAGjB,cAFa,MAAMF,EAAM,KAAK,IAA0CC,GAAM,EAAE,QAAAC,GAAQ,GAE5E,KAAK;AAAA,IACnB;AAAA,EAAA;AAEJ;ACpBO,MAAMC,IAA6C;AAAA,EACxD,QAAQ;AAAA,IACN,OAAO;AAAA,EAAA;AAAA,EAET,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,EAAA;AAEZ,GCZMC,wBAAa,QAAA;AAGZ,SAASC,IAA4B;AAC1C,MAAI;AACF,UAAM,EAAE,MAAAC,EAAA,IAASC,EAAA;AAEjB,IAAKH,EAAO,IAAIE,CAAI,MAClBA,EAAK,SAAS,iBAAiBH,CAAgB,GAC/CC,EAAO,IAAIE,CAAI;AAAA,EAEnB,QAAQ;AAAA,EAER;AACF;;;;ACLA,UAAME,IAAUD,EAAA,GACVE,IAAMV,EAAkBS,CAAO;AACrC,IAAAH,EAAA;AAEA,UAAMK,IAAIC,EAAa,eAAe,GAEhCT,IAASU,EAAiB,EAAE,GAC5BC,IAASD,EAA8B,EAAE,GACzCE,IAAUF,EAAI,EAAI,GAClBG,IAASH,EAAI,EAAK,GAElBI,IAAYR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BO,EAAArB,CAAA,EAAC,WAAA,CAAA,GAAA,CAAA;AAAA,UAAA;;;;MAIWI,EAAA,cAAnBmB,EAAwCF,EAAAI,CAAA,GAAA;AAAA;QAAX,MAAM;AAAA,MAAA,YACnCF,EAMEF,EAAAK,CAAA,GAAA;AAAA;oBAJSlC,EAAA;AAAA,sDAAAA,EAAM,QAAAmC;AAAA,QACf,MAAK;AAAA,QACJ,QAAQxB,EAAA;AAAA,QACR,WAAWkB,EAAAf,CAAA;AAAA,MAAA;;;;;;;;;AClEX,SAASsB,EAASC,IAA2B,IAAiB;AACnE,QAAMC,IAAOD,EAAQ,QAAQ;AAE7B,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,MAAAC;AAAA,IACA,QAAQ,CAAC,EAAE,MAAAA,GAAM,MAAM,iBAAiB,WAAWC,GAAc;AAAA,EAAA;AAErE;"}
@@ -0,0 +1,6 @@
1
+ import { Messages } from '@webx-ui/module-admin';
2
+ /**
3
+ * What this package says, in English — the same keys `webx-ui/module-settings` ships as
4
+ * `lang/en/*.php`, so a key never reaches the screen when a translation is missing.
5
+ */
6
+ export declare const settingsMessages: Record<string, Messages>;
@@ -0,0 +1,12 @@
1
+ import { AdminModule } from '@webx-ui/module-admin';
2
+ export interface SettingsOptions {
3
+ /** Where the section lives inside the panel. */
4
+ path?: string;
5
+ }
6
+ /**
7
+ * The settings, as a section of the panel.
8
+ *
9
+ * The id matches the module the server reports, which is what makes the entry appear in the
10
+ * navigation: a section shows up when both halves are installed.
11
+ */
12
+ export declare function settings(options?: SettingsOptions): AdminModule;
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .wx-settings[data-v-7b2af3ae]{display:flex;flex-direction:column;gap:var(--wx-space-16)}.wx-settings__head[data-v-7b2af3ae]{display:flex;align-items:center;justify-content:space-between;gap:var(--wx-space-12)}
@@ -0,0 +1,2 @@
1
+ /** Values keyed by the screen's field names, as stored: `general.project-name` is one key. */
2
+ export type SettingsValues = Record<string, unknown>;
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@webx-ui/module-settings",
3
+ "version": "0.1.0",
4
+ "description": "Site settings for the WebX UI admin panel: the section that draws the settings screen and saves it.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "*.css"
9
+ ],
10
+ "keywords": [
11
+ "webx-ui",
12
+ "vue",
13
+ "admin",
14
+ "settings"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/webx-ui/webx-ui.git",
19
+ "directory": "packages/module-settings"
20
+ },
21
+ "homepage": "https://webx-ui.github.io/webx-ui/guide/settings.html",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "main": "./dist/index.js",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "./style.css": "./dist/style.css",
37
+ "./dist/style.css": "./dist/style.css",
38
+ "./package.json": "./package.json"
39
+ },
40
+ "peerDependencies": {
41
+ "vue": "^3.5.0",
42
+ "vue-router": "^4.5.0"
43
+ },
44
+ "dependencies": {
45
+ "@webx-ui/core": "^0.17.0",
46
+ "@webx-ui/module-admin": "^0.3.1",
47
+ "@webx-ui/schema": "^0.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^24.10.1",
51
+ "@vitejs/plugin-vue": "^6.0.1",
52
+ "typescript": "^5.9.3",
53
+ "vite": "^7.1.14",
54
+ "vite-plugin-dts": "^4.5.4",
55
+ "vue": "^3.5.24",
56
+ "vue-router": "^4.5.1",
57
+ "vue-tsc": "^3.1.3"
58
+ },
59
+ "scripts": {
60
+ "build": "vite build",
61
+ "dev": "vite build --watch",
62
+ "typecheck": "vue-tsc -p tsconfig.json --noEmit"
63
+ }
64
+ }