@byline/admin 3.13.2 → 3.13.3

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.
@@ -13,12 +13,16 @@ const ArrayField = ({ field, defaultValue, path, disableSorting = false, content
13
13
  const { t } = useTranslation('byline-admin');
14
14
  const [items, setItems] = useState([]);
15
15
  useEffect(()=>{
16
- Array.isArray(defaultValue) ? setItems(defaultValue.map((item)=>({
16
+ const storeValue = getFieldValue(path);
17
+ const source = Array.isArray(storeValue) ? storeValue : defaultValue;
18
+ Array.isArray(source) ? setItems(source.map((item)=>({
17
19
  id: item && 'object' == typeof item && 'id' in item ? String(item.id) : item && 'object' == typeof item && '_id' in item ? String(item._id) : crypto.randomUUID(),
18
20
  data: item
19
21
  }))) : setItems([]);
20
22
  }, [
21
- defaultValue
23
+ defaultValue,
24
+ getFieldValue,
25
+ path
22
26
  ]);
23
27
  const handleDragEnd = ({ moveFromIndex, moveToIndex })=>{
24
28
  setItems((prev)=>moveItem(prev, moveFromIndex, moveToIndex));
@@ -25,12 +25,16 @@ const BlocksField = ({ field, defaultValue, path, contentLocale })=>{
25
25
  selectedBlockName
26
26
  ]);
27
27
  useEffect(()=>{
28
- Array.isArray(defaultValue) ? setItems(defaultValue.map((item)=>({
28
+ const storeValue = getFieldValue(path);
29
+ const source = Array.isArray(storeValue) ? storeValue : defaultValue;
30
+ Array.isArray(source) ? setItems(source.map((item)=>({
29
31
  id: item && 'object' == typeof item && '_id' in item ? String(item._id) : crypto.randomUUID(),
30
32
  data: item
31
33
  }))) : setItems([]);
32
34
  }, [
33
- defaultValue
35
+ defaultValue,
36
+ getFieldValue,
37
+ path
34
38
  ]);
35
39
  const handleDragEnd = ({ moveFromIndex, moveToIndex })=>{
36
40
  setItems((prev)=>moveItem(prev, moveFromIndex, moveToIndex));
@@ -33,3 +33,16 @@ export declare function getThemeMode(): ThemeMode;
33
33
  * override so the document follows `prefers-color-scheme` again.
34
34
  */
35
35
  export declare function setThemeMode(mode: ThemeMode): void;
36
+ /**
37
+ * Re-assert the stored theme on the live document without changing it.
38
+ *
39
+ * Byline admin shares the host's theme contract (the `theme` key + the
40
+ * `.dark`/`.light` class on `<html>`), so the surrounding host owns the
41
+ * before-first-paint application. But a host theme provider can re-apply
42
+ * its own (possibly stale, possibly forced) theme on navigation and
43
+ * clobber the admin user's stored choice. Calling this when the admin
44
+ * shell mounts re-applies the stored preference from the single source of
45
+ * truth — `localStorage` — making the admin area self-correcting
46
+ * regardless of how the host manages theme. No-op on the server.
47
+ */
48
+ export declare function applyStoredTheme(): void;
@@ -27,4 +27,9 @@ function setThemeMode(mode) {
27
27
  applyEffectiveTheme(mode);
28
28
  }
29
29
  }
30
- export { getThemeMode, setThemeMode };
30
+ function applyStoredTheme() {
31
+ if ("u" < typeof window) return;
32
+ const mode = getThemeMode();
33
+ applyEffectiveTheme('system' === mode ? systemPrefersDark() ? 'dark' : 'light' : mode);
34
+ }
35
+ export { applyStoredTheme, getThemeMode, setThemeMode };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@byline/admin",
3
3
  "private": false,
4
4
  "license": "MPL-2.0",
5
- "version": "3.13.2",
5
+ "version": "3.13.3",
6
6
  "engines": {
7
7
  "node": ">=20.9.0"
8
8
  },
@@ -122,6 +122,11 @@
122
122
  "import": "./dist/modules/admin-account/components/container.js",
123
123
  "require": "./dist/modules/admin-account/components/container.js"
124
124
  },
125
+ "./admin-account/components/theme": {
126
+ "types": "./dist/modules/admin-account/components/theme.d.ts",
127
+ "import": "./dist/modules/admin-account/components/theme.js",
128
+ "require": "./dist/modules/admin-account/components/theme.js"
129
+ },
125
130
  "./admin-account/components/update": {
126
131
  "types": "./dist/modules/admin-account/components/update.d.ts",
127
132
  "import": "./dist/modules/admin-account/components/update.js",
@@ -151,10 +156,10 @@
151
156
  "uuid": "^14.0.0",
152
157
  "zod": "^4.4.3",
153
158
  "zod-form-data": "^3.0.1",
154
- "@byline/auth": "3.13.2",
155
- "@byline/ui": "3.13.2",
156
- "@byline/core": "3.13.2",
157
- "@byline/i18n": "3.13.2"
159
+ "@byline/auth": "3.13.3",
160
+ "@byline/core": "3.13.3",
161
+ "@byline/i18n": "3.13.3",
162
+ "@byline/ui": "3.13.3"
158
163
  },
159
164
  "peerDependencies": {
160
165
  "react": "^19.0.0",
@@ -47,9 +47,17 @@ export const ArrayField = ({
47
47
  const [items, setItems] = useState<{ id: string; data: any }[]>([])
48
48
 
49
49
  useEffect(() => {
50
- if (Array.isArray(defaultValue)) {
50
+ // Prefer the live form-store value over `defaultValue` when seeding the
51
+ // rendered list. The store lives in FormProvider — above the tab layout —
52
+ // so it survives this field unmounting/remounting as the editor switches
53
+ // tabs; `defaultValue` is only the initial seed and is empty in create
54
+ // mode. Re-seeding from `defaultValue` on remount would drop items the
55
+ // editor had already added on an earlier visit to this tab.
56
+ const storeValue = getFieldValue(path)
57
+ const source = Array.isArray(storeValue) ? storeValue : defaultValue
58
+ if (Array.isArray(source)) {
51
59
  setItems(
52
- defaultValue.map((item: any) => ({
60
+ source.map((item: any) => ({
53
61
  id:
54
62
  item && typeof item === 'object' && 'id' in item
55
63
  ? String((item as { id: string }).id)
@@ -62,7 +70,7 @@ export const ArrayField = ({
62
70
  } else {
63
71
  setItems([])
64
72
  }
65
- }, [defaultValue])
73
+ }, [defaultValue, getFieldValue, path])
66
74
 
67
75
  const handleDragEnd = ({
68
76
  moveFromIndex,
@@ -73,9 +73,17 @@ export const BlocksField = ({
73
73
  }, [availableBlocks, selectedBlockName])
74
74
 
75
75
  useEffect(() => {
76
- if (Array.isArray(defaultValue)) {
76
+ // Prefer the live form-store value over `defaultValue` when seeding the
77
+ // rendered list. The store lives in FormProvider — above the tab layout —
78
+ // so it survives this field unmounting/remounting as the editor switches
79
+ // tabs; `defaultValue` is only the initial seed and is empty in create
80
+ // mode. Re-seeding from `defaultValue` on remount would drop blocks the
81
+ // editor had already added on an earlier visit to this tab.
82
+ const storeValue = getFieldValue(path)
83
+ const source = Array.isArray(storeValue) ? storeValue : defaultValue
84
+ if (Array.isArray(source)) {
77
85
  setItems(
78
- defaultValue.map((item: any) => ({
86
+ source.map((item: any) => ({
79
87
  id:
80
88
  item && typeof item === 'object' && '_id' in item
81
89
  ? String((item as { _id: string })._id)
@@ -86,7 +94,7 @@ export const BlocksField = ({
86
94
  } else {
87
95
  setItems([])
88
96
  }
89
- }, [defaultValue])
97
+ }, [defaultValue, getFieldValue, path])
90
98
 
91
99
  const handleDragEnd = ({
92
100
  moveFromIndex,
@@ -70,3 +70,21 @@ export function setThemeMode(mode: ThemeMode): void {
70
70
  applyEffectiveTheme(mode)
71
71
  }
72
72
  }
73
+
74
+ /**
75
+ * Re-assert the stored theme on the live document without changing it.
76
+ *
77
+ * Byline admin shares the host's theme contract (the `theme` key + the
78
+ * `.dark`/`.light` class on `<html>`), so the surrounding host owns the
79
+ * before-first-paint application. But a host theme provider can re-apply
80
+ * its own (possibly stale, possibly forced) theme on navigation and
81
+ * clobber the admin user's stored choice. Calling this when the admin
82
+ * shell mounts re-applies the stored preference from the single source of
83
+ * truth — `localStorage` — making the admin area self-correcting
84
+ * regardless of how the host manages theme. No-op on the server.
85
+ */
86
+ export function applyStoredTheme(): void {
87
+ if (typeof window === 'undefined') return
88
+ const mode = getThemeMode()
89
+ applyEffectiveTheme(mode === 'system' ? (systemPrefersDark() ? 'dark' : 'light') : mode)
90
+ }