@kilivi/payloadcms-theme-management 0.1.7 → 0.1.9

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/dist/index.d.ts CHANGED
@@ -13,7 +13,6 @@ export type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } fro
13
13
  export { DEFAULT_THEME_CONFIGURATION, resolveThemeConfiguration, } from './utils/resolveThemeConfiguration.js';
14
14
  export { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js';
15
15
  export { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js';
16
- export { ServerThemeInjector } from './components/ServerThemeInjector.js';
17
16
  export type { Mode, ThemeDefaults } from './providers/Theme/types.js';
18
17
  export { ThemeProvider } from './providers/Theme/index.js';
19
18
  export declare const ThemeManagementPlugin: (options?: ThemeManagementPluginOptions) => Plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,MAAM,EAAE,MAAM,SAAS,CAAA;AAEtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAA;AA2BnB,eAAO,MAAM,qBAAqB,GAAI,UAAS,4BAAiC,KAAG,MAqElF,CAAA;AAED,KAAK,iBAAiB,GAAG,MAAM,GAAG,8BAA8B,CAAA;AAEhE,eAAO,MAAM,uBAAuB,GAClC,UAAU,iBAAiB,KAC1B,OAAO,CAAC,sBAAsB,GAAG,IAAI,CA8CvC,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,WAAW,GAAG,IAEhE,CAAA;AAED,eAAO,MAAM,wBAAwB,QAAO,WAAW,EAEtD,CAAA;AAID,OAAO,EAAE,mBAAmB,EAA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MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,WAAW,GAAG,IAEhE,CAAA;AAED,eAAO,MAAM,wBAAwB,QAAO,WAAW,EAEtD,CAAA;AAID,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACtE,YAAY,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAC9F,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAExE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,eAAO,MAAM,qBAAqB,aAlJa,4BAA4B,KAAQ,MAkJzB,CAAA;AAC1D,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,aApJU,4BAA4B,KAAQ,MAoJtB,CAAA;AAE7D,eAAe,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -101,7 +101,6 @@ export { defaultThemePresets } from './presets.js';
101
101
  export { DEFAULT_THEME_CONFIGURATION, resolveThemeConfiguration } from './utils/resolveThemeConfiguration.js';
102
102
  export { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js';
103
103
  export { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js';
104
- export { ServerThemeInjector } from './components/ServerThemeInjector.js';
105
104
  export { ThemeProvider } from './providers/Theme/index.js';
106
105
  export const ThemeManagementPlugin = themeManagementPlugin;
107
106
  /** @deprecated use {@link themeManagementPlugin} */ export const themeConfigurationPlugin = themeManagementPlugin;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config, Field, Plugin } from 'payload'\r\nimport { createThemeConfigurationField } from './fields/themeConfigurationField.js'\r\nimport type { SiteThemeConfiguration } from './payload-types.js'\r\nimport type { ThemePreset } from './presets.js'\r\nimport { defaultThemePresets } from './presets.js'\r\nimport type {\r\n FetchThemeConfigurationOptions,\r\n ThemeManagementPluginOptions,\r\n} from './types.js'\r\n\r\nconst THEME_FIELD_NAME = 'themeConfiguration'\r\n\r\nconst removeExistingThemeField = (fields: Field[] = []): Field[] =>\r\n fields.filter((field) => {\r\n const candidate = field as { name?: unknown }\r\n return candidate?.name !== THEME_FIELD_NAME\r\n })\r\n\r\nconst upsertThemeField = (\r\n fields: Field[] | undefined,\r\n themeField: Field,\r\n enableLogging: boolean,\r\n): Field[] => {\r\n const sanitized = removeExistingThemeField(fields ?? [])\r\n\r\n if (enableLogging) {\r\n console.log('🎨 Theme Management Plugin: injecting theme configuration field')\r\n }\r\n\r\n return [...sanitized, themeField]\r\n}\r\n\r\nconst ensureCollectionsArray = (collections: Config['collections']): CollectionConfig[] =>\r\n Array.isArray(collections) ? collections : []\r\n\r\nexport const themeManagementPlugin = (options: ThemeManagementPluginOptions = {}): Plugin => {\r\n return (config: Config): Config => {\r\n const {\r\n enabled = true,\r\n targetCollection = 'site-settings',\r\n themePresets = defaultThemePresets,\r\n defaultTheme = 'cool',\r\n includeColorModeToggle = true,\r\n includeCustomCSS = true,\r\n includeBrandIdentity = false,\r\n enableAdvancedFeatures = true,\r\n enableLogging = false,\r\n } = options\r\n\r\n if (!enabled) {\r\n if (enableLogging) {\r\n console.log('🎨 Theme Management Plugin: disabled via options, skipping.')\r\n }\r\n return config\r\n }\r\n\r\n const themeField = createThemeConfigurationField({\r\n themePresets,\r\n defaultTheme,\r\n includeColorModeToggle,\r\n includeCustomCSS,\r\n includeBrandIdentity: includeBrandIdentity ?? false,\r\n enableAdvancedFeatures,\r\n })\r\n\r\n let collectionTouched = false\r\n\r\n const collections = ensureCollectionsArray(config.collections).map((collection) => {\r\n if (collection.slug !== targetCollection) {\r\n return collection\r\n }\r\n\r\n collectionTouched = true\r\n\r\n if (enableLogging) {\r\n console.log(\r\n `🎨 Theme Management Plugin: enhancing collection \"${collection.slug}\"`,\r\n )\r\n }\r\n\r\n const existingFields = Array.isArray(collection.fields) ? collection.fields : []\r\n\r\n const fields = upsertThemeField(existingFields, themeField, enableLogging)\r\n\r\n return {\r\n ...collection,\r\n fields,\r\n }\r\n })\r\n\r\n if (!collectionTouched) {\r\n if (enableLogging) {\r\n console.warn(\r\n `🎨 Theme Management Plugin: collection \"${targetCollection}\" was not found, leaving config untouched.`,\r\n )\r\n }\r\n return config\r\n }\r\n\r\n return {\r\n ...config,\r\n collections,\r\n }\r\n }\r\n}\r\n\r\ntype FetchOptionsInput = string | FetchThemeConfigurationOptions\r\n\r\nexport const fetchThemeConfiguration = async (\r\n options?: FetchOptionsInput,\r\n): Promise<SiteThemeConfiguration | null> => {\r\n const normalizedOptions =\r\n typeof options === 'string'\r\n ? { tenantSlug: options }\r\n : options ?? {}\r\n\r\n const {\r\n tenantSlug,\r\n collectionSlug = 'site-settings',\r\n depth,\r\n locale,\r\n draft,\r\n queryParams = {},\r\n } = normalizedOptions\r\n\r\n const params = new URLSearchParams({ limit: '1' })\r\n\r\n if (typeof depth === 'number') params.set('depth', String(depth))\r\n if (tenantSlug) params.set('tenant', tenantSlug)\r\n if (locale) params.set('locale', locale)\r\n if (draft) params.set('draft', 'true')\r\n\r\n Object.entries(queryParams).forEach(([key, value]) => {\r\n if (value === undefined) return\r\n params.set(key, String(value))\r\n })\r\n\r\n const url = `/api/${collectionSlug}?${params.toString()}`\r\n\r\n try {\r\n const response = await fetch(url)\r\n if (!response.ok) {\r\n throw new Error(`Failed to fetch theme configuration (status ${response.status})`)\r\n }\r\n\r\n const data = (await response.json()) as {\r\n docs?: Array<{ themeConfiguration?: SiteThemeConfiguration }>\r\n }\r\n\r\n const doc = data.docs?.[0]\r\n\r\n return doc?.themeConfiguration ?? null\r\n } catch (error) {\r\n console.warn('Failed to fetch theme configuration:', error)\r\n return null\r\n }\r\n}\r\n\r\nexport const getThemePreset = (themeName: string): ThemePreset | null => {\r\n return defaultThemePresets.find((preset) => preset.name === themeName) || null\r\n}\r\n\r\nexport const getAvailableThemePresets = (): ThemePreset[] => {\r\n return defaultThemePresets\r\n}\r\n\r\n\r\n\r\nexport { defaultThemePresets } from './presets.js'\r\nexport type { ThemePreset, ThemeTypographyPreset } from './presets.js'\r\nexport type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } from './types.js'\r\nexport {\r\n DEFAULT_THEME_CONFIGURATION,\r\n resolveThemeConfiguration,\r\n} from './utils/resolveThemeConfiguration.js'\r\nexport { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js'\r\nexport { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js'\r\nexport { ServerThemeInjector } from './components/ServerThemeInjector.js'\r\n\r\nexport type { Mode, ThemeDefaults } from './providers/Theme/types.js'\r\nexport { ThemeProvider } from './providers/Theme/index.js'\r\n\r\nexport const ThemeManagementPlugin = themeManagementPlugin\r\n/** @deprecated use {@link themeManagementPlugin} */\r\nexport const themeConfigurationPlugin = themeManagementPlugin\r\n\r\nexport default themeManagementPlugin"],"names":["createThemeConfigurationField","defaultThemePresets","THEME_FIELD_NAME","removeExistingThemeField","fields","filter","field","candidate","name","upsertThemeField","themeField","enableLogging","sanitized","console","log","ensureCollectionsArray","collections","Array","isArray","themeManagementPlugin","options","config","enabled","targetCollection","themePresets","defaultTheme","includeColorModeToggle","includeCustomCSS","includeBrandIdentity","enableAdvancedFeatures","collectionTouched","map","collection","slug","existingFields","warn","fetchThemeConfiguration","normalizedOptions","tenantSlug","collectionSlug","depth","locale","draft","queryParams","params","URLSearchParams","limit","set","String","Object","entries","forEach","key","value","undefined","url","toString","response","fetch","ok","Error","status","data","json","doc","docs","themeConfiguration","error","getThemePreset","themeName","find","preset","getAvailableThemePresets","DEFAULT_THEME_CONFIGURATION","resolveThemeConfiguration","generateThemeColorsCss","hexToHsl","generateThemeCSS","getThemeStyles","ServerThemeInjector","ThemeProvider","ThemeManagementPlugin","themeConfigurationPlugin"],"mappings":"AACA,SAASA,6BAA6B,QAAQ,sCAAqC;AAGnF,SAASC,mBAAmB,QAAQ,eAAc;AAMlD,MAAMC,mBAAmB;AAEzB,MAAMC,2BAA2B,CAACC,SAAkB,EAAE,GACpDA,OAAOC,MAAM,CAAC,CAACC;QACb,MAAMC,YAAYD;QAClB,OAAOC,WAAWC,SAASN;IAC7B;AAEF,MAAMO,mBAAmB,CACvBL,QACAM,YACAC;IAEA,MAAMC,YAAYT,yBAAyBC,UAAU,EAAE;IAEvD,IAAIO,eAAe;QACnBE,QAAQC,GAAG,CAAC;IACZ;IAEA,OAAO;WAAIF;QAAWF;KAAW;AACnC;AAEA,MAAMK,yBAAyB,CAACC,cAC9BC,MAAMC,OAAO,CAACF,eAAeA,cAAc,EAAE;AAE/C,OAAO,MAAMG,wBAAwB,CAACC,UAAwC,CAAC,CAAC;IAC9E,OAAO,CAACC;QACN,MAAM,EACJC,UAAU,IAAI,EACdC,mBAAmB,eAAe,EAClCC,eAAevB,mBAAmB,EAClCwB,eAAe,MAAM,EACrBC,yBAAyB,IAAI,EAC7BC,mBAAmB,IAAI,EACvBC,uBAAuB,KAAK,EAC5BC,yBAAyB,IAAI,EAC7BlB,gBAAgB,KAAK,EACtB,GAAGS;QAEJ,IAAI,CAACE,SAAS;YACZ,IAAIX,eAAe;gBACvBE,QAAQC,GAAG,CAAC;YACR;YACA,OAAOO;QACT;QAEA,MAAMX,aAAaV,8BAA8B;YAC/CwB;YACAC;YACAC;YACAC;YACAC,sBAAsBA,wBAAwB;YAC9CC;QACF;QAEA,IAAIC,oBAAoB;QAExB,MAAMd,cAAcD,uBAAuBM,OAAOL,WAAW,EAAEe,GAAG,CAAC,CAACC;YAClE,IAAIA,WAAWC,IAAI,KAAKV,kBAAkB;gBACxC,OAAOS;YACT;YAEAF,oBAAoB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IAEzD,IAAI;QACF,MAAMC,WAAW,MAAMC,MAAMH;QAC7B,IAAI,CAACE,SAASE,EAAE,EAAE;YAChB,MAAM,IAAIC,MAAM,CAAC,4CAA4C,EAAEH,SAASI,MAAM,CAAC,CAAC,CAAC;QACnF;QAEA,MAAMC,OAAQ,MAAML,SAASM,IAAI;QAIjC,MAAMC,MAAMF,KAAKG,IAAI,EAAE,CAAC,EAAE;QAE1B,OAAOD,KAAKE,sBAAsB;IACpC,EAAE,OAAOC,OAAO;QACdtD,QAAQsB,IAAI,CAAC,wCAAwCgC;QACrD,OAAO;IACT;AACF,EAAC;AAED,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,OAAOpE,oBAAoBqE,IAAI,CAAC,CAACC,SAAWA,OAAO/D,IAAI,KAAK6D,cAAc;AAC5E,EAAC;AAED,OAAO,MAAMG,2BAA2B;IACtC,OAAOvE;AACT,EAAC;AAID,SAASA,mBAAmB,QAAQ,eAAc;AAGlD,SACEwE,2BAA2B,EAC3BC,yBAAyB,QACpB,uCAAsC;AAC7C,SAASC,sBAAsB,EAAEC,QAAQ,QAAQ,yBAAwB;AACzE,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,wBAAuB;AACxE,SAASC,mBAAmB,QAAQ,sCAAqC;AAGzE,SAASC,aAAa,QAAQ,6BAA4B;AAE1D,OAAO,MAAMC,wBAAwB9D,sBAAqB;AAC1D,kDAAkD,GAClD,OAAO,MAAM+D,2BAA2B/D,sBAAqB;AAE7D,eAAeA,sBAAqB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config, Field, Plugin } from 'payload'\r\nimport { createThemeConfigurationField } from './fields/themeConfigurationField.js'\r\nimport type { SiteThemeConfiguration } from './payload-types.js'\r\nimport type { ThemePreset } from './presets.js'\r\nimport { defaultThemePresets } from './presets.js'\r\nimport type {\r\n FetchThemeConfigurationOptions,\r\n ThemeManagementPluginOptions,\r\n} from './types.js'\r\n\r\nconst THEME_FIELD_NAME = 'themeConfiguration'\r\n\r\nconst removeExistingThemeField = (fields: Field[] = []): Field[] =>\r\n fields.filter((field) => {\r\n const candidate = field as { name?: unknown }\r\n return candidate?.name !== THEME_FIELD_NAME\r\n })\r\n\r\nconst upsertThemeField = (\r\n fields: Field[] | undefined,\r\n themeField: Field,\r\n enableLogging: boolean,\r\n): Field[] => {\r\n const sanitized = removeExistingThemeField(fields ?? [])\r\n\r\n if (enableLogging) {\r\n console.log('🎨 Theme Management Plugin: injecting theme configuration field')\r\n }\r\n\r\n return [...sanitized, themeField]\r\n}\r\n\r\nconst ensureCollectionsArray = (collections: Config['collections']): CollectionConfig[] =>\r\n Array.isArray(collections) ? collections : []\r\n\r\nexport const themeManagementPlugin = (options: ThemeManagementPluginOptions = {}): Plugin => {\r\n return (config: Config): Config => {\r\n const {\r\n enabled = true,\r\n targetCollection = 'site-settings',\r\n themePresets = defaultThemePresets,\r\n defaultTheme = 'cool',\r\n includeColorModeToggle = true,\r\n includeCustomCSS = true,\r\n includeBrandIdentity = false,\r\n enableAdvancedFeatures = true,\r\n enableLogging = false,\r\n } = options\r\n\r\n if (!enabled) {\r\n if (enableLogging) {\r\n console.log('🎨 Theme Management Plugin: disabled via options, skipping.')\r\n }\r\n return config\r\n }\r\n\r\n const themeField = createThemeConfigurationField({\r\n themePresets,\r\n defaultTheme,\r\n includeColorModeToggle,\r\n includeCustomCSS,\r\n includeBrandIdentity: includeBrandIdentity ?? false,\r\n enableAdvancedFeatures,\r\n })\r\n\r\n let collectionTouched = false\r\n\r\n const collections = ensureCollectionsArray(config.collections).map((collection) => {\r\n if (collection.slug !== targetCollection) {\r\n return collection\r\n }\r\n\r\n collectionTouched = true\r\n\r\n if (enableLogging) {\r\n console.log(\r\n `🎨 Theme Management Plugin: enhancing collection \"${collection.slug}\"`,\r\n )\r\n }\r\n\r\n const existingFields = Array.isArray(collection.fields) ? collection.fields : []\r\n\r\n const fields = upsertThemeField(existingFields, themeField, enableLogging)\r\n\r\n return {\r\n ...collection,\r\n fields,\r\n }\r\n })\r\n\r\n if (!collectionTouched) {\r\n if (enableLogging) {\r\n console.warn(\r\n `🎨 Theme Management Plugin: collection \"${targetCollection}\" was not found, leaving config untouched.`,\r\n )\r\n }\r\n return config\r\n }\r\n\r\n return {\r\n ...config,\r\n collections,\r\n }\r\n }\r\n}\r\n\r\ntype FetchOptionsInput = string | FetchThemeConfigurationOptions\r\n\r\nexport const fetchThemeConfiguration = async (\r\n options?: FetchOptionsInput,\r\n): Promise<SiteThemeConfiguration | null> => {\r\n const normalizedOptions =\r\n typeof options === 'string'\r\n ? { tenantSlug: options }\r\n : options ?? {}\r\n\r\n const {\r\n tenantSlug,\r\n collectionSlug = 'site-settings',\r\n depth,\r\n locale,\r\n draft,\r\n queryParams = {},\r\n } = normalizedOptions\r\n\r\n const params = new URLSearchParams({ limit: '1' })\r\n\r\n if (typeof depth === 'number') params.set('depth', String(depth))\r\n if (tenantSlug) params.set('tenant', tenantSlug)\r\n if (locale) params.set('locale', locale)\r\n if (draft) params.set('draft', 'true')\r\n\r\n Object.entries(queryParams).forEach(([key, value]) => {\r\n if (value === undefined) return\r\n params.set(key, String(value))\r\n })\r\n\r\n const url = `/api/${collectionSlug}?${params.toString()}`\r\n\r\n try {\r\n const response = await fetch(url)\r\n if (!response.ok) {\r\n throw new Error(`Failed to fetch theme configuration (status ${response.status})`)\r\n }\r\n\r\n const data = (await response.json()) as {\r\n docs?: Array<{ themeConfiguration?: SiteThemeConfiguration }>\r\n }\r\n\r\n const doc = data.docs?.[0]\r\n\r\n return doc?.themeConfiguration ?? null\r\n } catch (error) {\r\n console.warn('Failed to fetch theme configuration:', error)\r\n return null\r\n }\r\n}\r\n\r\nexport const getThemePreset = (themeName: string): ThemePreset | null => {\r\n return defaultThemePresets.find((preset) => preset.name === themeName) || null\r\n}\r\n\r\nexport const getAvailableThemePresets = (): ThemePreset[] => {\r\n return defaultThemePresets\r\n}\r\n\r\n\r\n\r\nexport { defaultThemePresets } from './presets.js'\r\nexport type { ThemePreset, ThemeTypographyPreset } from './presets.js'\r\nexport type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } from './types.js'\r\nexport {\r\n DEFAULT_THEME_CONFIGURATION,\r\n resolveThemeConfiguration,\r\n} from './utils/resolveThemeConfiguration.js'\r\nexport { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js'\r\nexport { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js'\r\n\r\nexport type { Mode, ThemeDefaults } from './providers/Theme/types.js'\r\nexport { ThemeProvider } from './providers/Theme/index.js'\r\n\r\nexport const ThemeManagementPlugin = themeManagementPlugin\r\n/** @deprecated use {@link themeManagementPlugin} */\r\nexport const themeConfigurationPlugin = themeManagementPlugin\r\n\r\nexport default themeManagementPlugin"],"names":["createThemeConfigurationField","defaultThemePresets","THEME_FIELD_NAME","removeExistingThemeField","fields","filter","field","candidate","name","upsertThemeField","themeField","enableLogging","sanitized","console","log","ensureCollectionsArray","collections","Array","isArray","themeManagementPlugin","options","config","enabled","targetCollection","themePresets","defaultTheme","includeColorModeToggle","includeCustomCSS","includeBrandIdentity","enableAdvancedFeatures","collectionTouched","map","collection","slug","existingFields","warn","fetchThemeConfiguration","normalizedOptions","tenantSlug","collectionSlug","depth","locale","draft","queryParams","params","URLSearchParams","limit","set","String","Object","entries","forEach","key","value","undefined","url","toString","response","fetch","ok","Error","status","data","json","doc","docs","themeConfiguration","error","getThemePreset","themeName","find","preset","getAvailableThemePresets","DEFAULT_THEME_CONFIGURATION","resolveThemeConfiguration","generateThemeColorsCss","hexToHsl","generateThemeCSS","getThemeStyles","ThemeProvider","ThemeManagementPlugin","themeConfigurationPlugin"],"mappings":"AACA,SAASA,6BAA6B,QAAQ,sCAAqC;AAGnF,SAASC,mBAAmB,QAAQ,eAAc;AAMlD,MAAMC,mBAAmB;AAEzB,MAAMC,2BAA2B,CAACC,SAAkB,EAAE,GACpDA,OAAOC,MAAM,CAAC,CAACC;QACb,MAAMC,YAAYD;QAClB,OAAOC,WAA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QAAQsB,IAAI,CAAC,wCAAwCgC;QACrD,OAAO;IACT;AACF,EAAC;AAED,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,OAAOpE,oBAAoBqE,IAAI,CAAC,CAACC,SAAWA,OAAO/D,IAAI,KAAK6D,cAAc;AAC5E,EAAC;AAED,OAAO,MAAMG,2BAA2B;IACtC,OAAOvE;AACT,EAAC;AAID,SAASA,mBAAmB,QAAQ,eAAc;AAGlD,SACEwE,2BAA2B,EAC3BC,yBAAyB,QACpB,uCAAsC;AAC7C,SAASC,sBAAsB,EAAEC,QAAQ,QAAQ,yBAAwB;AACzE,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,wBAAuB;AAGxE,SAASC,aAAa,QAAQ,6BAA4B;AAE1D,OAAO,MAAMC,wBAAwB7D,sBAAqB;AAC1D,kDAAkD,GAClD,OAAO,MAAM8D,2BAA2B9D,sBAAqB;AAE7D,eAAeA,sBAAqB"}
package/dist/server.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import 'server-only';
1
2
  export { ServerThemeInjector } from './components/ServerThemeInjector.js';
2
3
  export { createFallbackCriticalCSS, generateThemePreloadLinks, getThemeCriticalCSS, getThemeCSSPath, } from './utils/themeAssets.js';
3
4
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAEzE,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAEzE,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAA"}
package/dist/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ import 'server-only';
1
2
  export { ServerThemeInjector } from './components/ServerThemeInjector.js';
2
3
  export { createFallbackCriticalCSS, generateThemePreloadLinks, getThemeCriticalCSS, getThemeCSSPath } from './utils/themeAssets.js';
3
4
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["export { ServerThemeInjector } from './components/ServerThemeInjector.js'\r\n\r\nexport {\r\n createFallbackCriticalCSS,\r\n generateThemePreloadLinks,\r\n getThemeCriticalCSS,\r\n getThemeCSSPath,\r\n} from './utils/themeAssets.js'\r\n"],"names":["ServerThemeInjector","createFallbackCriticalCSS","generateThemePreloadLinks","getThemeCriticalCSS","getThemeCSSPath"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,sCAAqC;AAEzE,SACEC,yBAAyB,EACzBC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,QACV,yBAAwB"}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only'\r\n\r\nexport { ServerThemeInjector } from './components/ServerThemeInjector.js'\r\n\r\nexport {\r\n createFallbackCriticalCSS,\r\n generateThemePreloadLinks,\r\n getThemeCriticalCSS,\r\n getThemeCSSPath,\r\n} from './utils/themeAssets.js'\r\n"],"names":["ServerThemeInjector","createFallbackCriticalCSS","generateThemePreloadLinks","getThemeCriticalCSS","getThemeCSSPath"],"mappings":"AAAA,OAAO,cAAa;AAEpB,SAASA,mBAAmB,QAAQ,sCAAqC;AAEzE,SACEC,yBAAyB,EACzBC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,QACV,yBAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kilivi/payloadcms-theme-management",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Theme configuration plugin for Payload CMS v3",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,7 @@
11
11
  "types": "./dist/index.d.ts"
12
12
  },
13
13
  "./server": {
14
+ "react-server": "./dist/server.js",
14
15
  "import": "./dist/server.js",
15
16
  "types": "./dist/server.d.ts"
16
17
  },
@@ -55,19 +56,22 @@
55
56
  "devDependencies": {
56
57
  "@payloadcms/db-mongodb": "^3.0.0",
57
58
  "@payloadcms/richtext-lexical": "^3.0.0",
59
+ "@swc/cli": "^0.1.65",
60
+ "@swc/core": "^1.6.3",
58
61
  "@types/react": "^18.3.12",
62
+ "copyfiles": "^2.4.1",
59
63
  "payload": "^3.58.0",
60
64
  "react": "^19.0.0",
61
65
  "react-dom": "^19.0.0",
62
- "typescript": "^5.5.3",
63
- "copyfiles": "^2.4.1",
64
- "@swc/cli": "^0.1.65",
65
- "@swc/core": "^1.6.3",
66
- "rimraf": "^5.0.5"
66
+ "rimraf": "^5.0.5",
67
+ "typescript": "^5.5.3"
67
68
  },
68
69
  "publishConfig": {
69
70
  "access": "public"
70
71
  },
72
+ "dependencies": {
73
+ "server-only": "^0.0.1"
74
+ },
71
75
  "scripts": {
72
76
  "build": "pnpm run clean && pnpm run compile && pnpm run copyfiles",
73
77
  "compile": "swc src -d dist --config-file .swcrc && tsc",