@jhits/plugin-content 0.0.16 → 0.0.18

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.
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGxD,MAAM,WAAW,sBAAsB;IACnC,oEAAoE;IACpE,KAAK,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,CAAA;KAAE,CAAC,CAAC;IACxC,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAClC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,sBAAsB,GAC/B,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGxD,MAAM,WAAW,sBAAsB;IACnC,oEAAoE;IACpE,KAAK,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,CAAA;KAAE,CAAC,CAAC;IACxC,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAClC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,sBAAsB,GAC/B,OAAO,CAAC,YAAY,CAAC,CA6DvB"}
@@ -16,7 +16,6 @@ export async function handleContentApi(req, path, config) {
16
16
  const method = req.method;
17
17
  const safePath = Array.isArray(path) ? path : [];
18
18
  const route = safePath.length > 0 ? safePath[0] : '';
19
- console.log(`[ContentApiRouter] method=${method}, path=${JSON.stringify(safePath)}, route=${route}, url=${req.url}`);
20
19
  try {
21
20
  // Route: /api/plugin-content/save
22
21
  if (route === 'save') {
@@ -1,8 +1,10 @@
1
1
  interface TranslationEditorProps {
2
2
  messages: Record<string, any>;
3
3
  locale: string;
4
+ apiBaseUrl?: string;
5
+ siteId?: string;
4
6
  }
5
- declare function TranslationEditorInner({ messages: initialMessages, locale: initialLocale }: TranslationEditorProps): import("react/jsx-runtime").JSX.Element | null;
7
+ declare function TranslationEditorInner({ messages: initialMessages, locale: initialLocale, apiBaseUrl, siteId }: TranslationEditorProps): import("react/jsx-runtime").JSX.Element | null;
6
8
  export default TranslationEditorInner;
7
9
  export type { TranslationEditorProps };
8
10
  //# sourceMappingURL=TranslationEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TranslationEditor.d.ts","sourceRoot":"","sources":["../../src/components/TranslationEditor.tsx"],"names":[],"mappings":"AAQA,UAAU,sBAAsB;IAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,iBAAS,sBAAsB,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,sBAAsB,kDA8S3G;AAeD,eAAe,sBAAsB,CAAC;AACtC,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
1
+ {"version":3,"file":"TranslationEditor.d.ts","sourceRoot":"","sources":["../../src/components/TranslationEditor.tsx"],"names":[],"mappings":"AAQA,UAAU,sBAAsB;IAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iBAAS,sBAAsB,CAAC,EAC5B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,aAAa,EACrB,UAAkC,EAClC,MAAkB,EACrB,EAAE,sBAAsB,kDAoTxB;AAeD,eAAe,sBAAsB,CAAC;AACtC,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
@@ -5,7 +5,7 @@ import { useState, useEffect, useMemo, useRef } from 'react';
5
5
  import { motion, AnimatePresence } from 'framer-motion';
6
6
  import { X, Globe, Search, ChevronRight, Plus, CornerDownRight, ShieldCheck, Lock, Bold, Italic, Type } from 'lucide-react';
7
7
  import { parse } from '../utils/parser';
8
- function TranslationEditorInner({ messages: initialMessages, locale: initialLocale }) {
8
+ function TranslationEditorInner({ messages: initialMessages, locale: initialLocale, apiBaseUrl = '/api/plugin-content', siteId = 'default' }) {
9
9
  const router = useRouter();
10
10
  const pathname = usePathname();
11
11
  const [mounted, setMounted] = useState(false);
@@ -56,7 +56,9 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
56
56
  useEffect(() => {
57
57
  async function checkAuth() {
58
58
  try {
59
- const res = await fetch('/api/plugin-dep/me');
59
+ // Get the base dashboard API URL (strip plugin-content if present)
60
+ const baseApi = apiBaseUrl.replace('/plugin-content', '');
61
+ const res = await fetch(`${baseApi}/plugin-dep/me`);
60
62
  const data = await res.json();
61
63
  if (data.loggedIn)
62
64
  setUserData(data.user);
@@ -69,7 +71,7 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
69
71
  }
70
72
  }
71
73
  checkAuth();
72
- }, []);
74
+ }, [apiBaseUrl]);
73
75
  useEffect(() => {
74
76
  const handleLocaleUpdate = (event) => {
75
77
  if (event.detail.locale === initialLocale) {
@@ -166,10 +168,14 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
166
168
  const handleSave = async () => {
167
169
  setSaving(true);
168
170
  try {
169
- const res = await fetch('/api/plugin-content/save', {
171
+ const res = await fetch(`${apiBaseUrl}/save`, {
170
172
  method: 'POST',
171
173
  headers: { 'Content-Type': 'application/json' },
172
- body: JSON.stringify({ locale: initialLocale, messages: jsonData }),
174
+ body: JSON.stringify({
175
+ locale: initialLocale,
176
+ messages: jsonData,
177
+ siteId
178
+ }),
173
179
  });
174
180
  if (res.ok) {
175
181
  router.refresh();
package/dist/index.d.ts CHANGED
@@ -9,6 +9,10 @@ export interface ContentPluginProps {
9
9
  locale?: string;
10
10
  /** Messages object - can be passed explicitly or will be fetched from context */
11
11
  messages?: Record<string, any>;
12
+ /** API base URL for the dashboard */
13
+ apiBaseUrl?: string;
14
+ /** Site identifier for multi-tenant setups */
15
+ siteId?: string;
12
16
  }
13
17
  /**
14
18
  * Content Plugin Component
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,MAAM,WAAW,kBAAkB;IAC/B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAoBD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,kDAoB9D;AAkBD,OAAO,EAAE,aAAa,EAAE,CAAC;AAGzB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,C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,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAG7E,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACtF,YAAY,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAG/E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@
6
6
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
7
7
  import { useState, useEffect, lazy, Suspense } from 'react';
8
8
  const TranslationEditor = lazy(() => import('./components/TranslationEditor'));
9
- function ContentPluginWithIntl({ locale, messages }) {
10
- return (_jsx(Suspense, { fallback: null, children: _jsx(TranslationEditor, { messages: messages, locale: locale }) }));
9
+ function ContentPluginWithIntl({ locale, messages, apiBaseUrl, siteId }) {
10
+ return (_jsx(Suspense, { fallback: null, children: _jsx(TranslationEditor, { messages: messages, locale: locale, apiBaseUrl: apiBaseUrl, siteId: siteId }) }));
11
11
  }
12
12
  function ClientOnly({ children }) {
13
13
  const [mounted, setMounted] = useState(false);
@@ -21,22 +21,22 @@ function ClientOnly({ children }) {
21
21
  * Renders the translation editor for editing website content
22
22
  */
23
23
  export default function ContentPlugin(props) {
24
- const { enabled = true, locale, messages } = props;
24
+ const { enabled = true, locale, messages, apiBaseUrl, siteId = 'default' } = props;
25
25
  if (!enabled)
26
26
  return null;
27
27
  // If locale and messages are provided as props, use them directly
28
28
  if (locale && messages) {
29
- return (_jsx(ClientOnly, { children: _jsx(ContentPluginWithIntl, { locale: locale, messages: messages }) }));
29
+ return (_jsx(ClientOnly, { children: _jsx(ContentPluginWithIntl, { locale: locale, messages: messages, apiBaseUrl: apiBaseUrl, siteId: siteId }) }));
30
30
  }
31
31
  // Otherwise, try to use context (for backward compatibility)
32
- return (_jsx(ClientOnly, { children: _jsx(ContentPluginWithIntlFallback, {}) }));
32
+ return (_jsx(ClientOnly, { children: _jsx(ContentPluginWithIntlFallback, { apiBaseUrl: apiBaseUrl, siteId: siteId }) }));
33
33
  }
34
- function ContentPluginWithIntlFallback() {
34
+ function ContentPluginWithIntlFallback({ apiBaseUrl, siteId }) {
35
35
  // Dynamic import to avoid SSR issues with next-intl hooks
36
36
  const { useMessages, useLocale, NextIntlClientProvider } = require('next-intl');
37
37
  const messages = useMessages();
38
38
  const locale = useLocale();
39
- return (_jsx(NextIntlClientProvider, { locale: locale, messages: messages, children: _jsx(Suspense, { fallback: null, children: _jsx(TranslationEditor, { messages: messages, locale: locale }) }) }));
39
+ return (_jsx(NextIntlClientProvider, { locale: locale, messages: messages, children: _jsx(Suspense, { fallback: null, children: _jsx(TranslationEditor, { messages: messages, locale: locale, apiBaseUrl: apiBaseUrl, siteId: siteId }) }) }));
40
40
  }
41
41
  // Export named export for flexibility
42
42
  export { ContentPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhits/plugin-content",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Content management and localization plugin for the JHITS ecosystem",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/api/router.ts CHANGED
@@ -33,8 +33,6 @@ export async function handleContentApi(
33
33
  const safePath = Array.isArray(path) ? path : [];
34
34
  const route = safePath.length > 0 ? safePath[0] : '';
35
35
 
36
- console.log(`[ContentApiRouter] method=${method}, path=${JSON.stringify(safePath)}, route=${route}, url=${req.url}`);
37
-
38
36
  try {
39
37
  // Route: /api/plugin-content/save
40
38
  if (route === 'save') {
@@ -9,9 +9,16 @@ import { parse } from '../utils/parser';
9
9
  interface TranslationEditorProps {
10
10
  messages: Record<string, any>;
11
11
  locale: string;
12
+ apiBaseUrl?: string;
13
+ siteId?: string;
12
14
  }
13
15
 
14
- function TranslationEditorInner({ messages: initialMessages, locale: initialLocale }: TranslationEditorProps) {
16
+ function TranslationEditorInner({
17
+ messages: initialMessages,
18
+ locale: initialLocale,
19
+ apiBaseUrl = '/api/plugin-content',
20
+ siteId = 'default'
21
+ }: TranslationEditorProps) {
15
22
  const router = useRouter();
16
23
  const pathname = usePathname();
17
24
  const [mounted, setMounted] = useState(false);
@@ -65,7 +72,9 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
65
72
  useEffect(() => {
66
73
  async function checkAuth() {
67
74
  try {
68
- const res = await fetch('/api/plugin-dep/me');
75
+ // Get the base dashboard API URL (strip plugin-content if present)
76
+ const baseApi = apiBaseUrl.replace('/plugin-content', '');
77
+ const res = await fetch(`${baseApi}/plugin-dep/me`);
69
78
  const data = await res.json();
70
79
  if (data.loggedIn) setUserData(data.user);
71
80
  } catch (err) {
@@ -75,7 +84,7 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
75
84
  }
76
85
  }
77
86
  checkAuth();
78
- }, []);
87
+ }, [apiBaseUrl]);
79
88
 
80
89
  useEffect(() => {
81
90
  const handleLocaleUpdate = (event: CustomEvent) => {
@@ -162,10 +171,14 @@ function TranslationEditorInner({ messages: initialMessages, locale: initialLoca
162
171
  const handleSave = async () => {
163
172
  setSaving(true);
164
173
  try {
165
- const res = await fetch('/api/plugin-content/save', {
174
+ const res = await fetch(`${apiBaseUrl}/save`, {
166
175
  method: 'POST',
167
176
  headers: { 'Content-Type': 'application/json' },
168
- body: JSON.stringify({ locale: initialLocale, messages: jsonData }),
177
+ body: JSON.stringify({
178
+ locale: initialLocale,
179
+ messages: jsonData,
180
+ siteId
181
+ }),
169
182
  });
170
183
  if (res.ok) {
171
184
  router.refresh();
@@ -330,5 +343,3 @@ function getFlattenedPaths(obj: any, prefix = ''): { path: string; value: string
330
343
 
331
344
  export default TranslationEditorInner;
332
345
  export type { TranslationEditorProps };
333
-
334
-
package/src/index.tsx CHANGED
@@ -16,12 +16,31 @@ export interface ContentPluginProps {
16
16
  locale?: string;
17
17
  /** Messages object - can be passed explicitly or will be fetched from context */
18
18
  messages?: Record<string, any>;
19
+ /** API base URL for the dashboard */
20
+ apiBaseUrl?: string;
21
+ /** Site identifier for multi-tenant setups */
22
+ siteId?: string;
19
23
  }
20
24
 
21
- function ContentPluginWithIntl({ locale, messages }: { locale: string; messages: Record<string, any> }) {
25
+ function ContentPluginWithIntl({
26
+ locale,
27
+ messages,
28
+ apiBaseUrl,
29
+ siteId
30
+ }: {
31
+ locale: string;
32
+ messages: Record<string, any>;
33
+ apiBaseUrl?: string;
34
+ siteId?: string;
35
+ }) {
22
36
  return (
23
37
  <Suspense fallback={null}>
24
- <TranslationEditor messages={messages} locale={locale} />
38
+ <TranslationEditor
39
+ messages={messages}
40
+ locale={locale}
41
+ apiBaseUrl={apiBaseUrl}
42
+ siteId={siteId}
43
+ />
25
44
  </Suspense>
26
45
  );
27
46
  }
@@ -41,7 +60,7 @@ function ClientOnly({ children }: { children: React.ReactNode }) {
41
60
  * Renders the translation editor for editing website content
42
61
  */
43
62
  export default function ContentPlugin(props: ContentPluginProps) {
44
- const { enabled = true, locale, messages } = props;
63
+ const { enabled = true, locale, messages, apiBaseUrl, siteId = 'default' } = props;
45
64
 
46
65
  if (!enabled) return null;
47
66
 
@@ -49,7 +68,12 @@ export default function ContentPlugin(props: ContentPluginProps) {
49
68
  if (locale && messages) {
50
69
  return (
51
70
  <ClientOnly>
52
- <ContentPluginWithIntl locale={locale} messages={messages} />
71
+ <ContentPluginWithIntl
72
+ locale={locale}
73
+ messages={messages}
74
+ apiBaseUrl={apiBaseUrl}
75
+ siteId={siteId}
76
+ />
53
77
  </ClientOnly>
54
78
  );
55
79
  }
@@ -57,12 +81,12 @@ export default function ContentPlugin(props: ContentPluginProps) {
57
81
  // Otherwise, try to use context (for backward compatibility)
58
82
  return (
59
83
  <ClientOnly>
60
- <ContentPluginWithIntlFallback />
84
+ <ContentPluginWithIntlFallback apiBaseUrl={apiBaseUrl} siteId={siteId} />
61
85
  </ClientOnly>
62
86
  );
63
87
  }
64
88
 
65
- function ContentPluginWithIntlFallback() {
89
+ function ContentPluginWithIntlFallback({ apiBaseUrl, siteId }: { apiBaseUrl?: string; siteId?: string }) {
66
90
  // Dynamic import to avoid SSR issues with next-intl hooks
67
91
  const { useMessages, useLocale, NextIntlClientProvider } = require('next-intl');
68
92
  const messages = useMessages();
@@ -71,7 +95,12 @@ function ContentPluginWithIntlFallback() {
71
95
  return (
72
96
  <NextIntlClientProvider locale={locale} messages={messages}>
73
97
  <Suspense fallback={null}>
74
- <TranslationEditor messages={messages} locale={locale} />
98
+ <TranslationEditor
99
+ messages={messages}
100
+ locale={locale}
101
+ apiBaseUrl={apiBaseUrl}
102
+ siteId={siteId}
103
+ />
75
104
  </Suspense>
76
105
  </NextIntlClientProvider>
77
106
  );