@nodehive/nextjs 0.6.1 → 0.7.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.
Files changed (66) hide show
  1. package/README.md +9 -0
  2. package/dist/puck-editor/index.d.ts +1 -1
  3. package/dist/puck-editor/index.js +1 -1
  4. package/dist/puck-editor/index.js.map +1 -1
  5. package/dist/puck-editor/internal/api/client.d.ts +4 -4
  6. package/dist/puck-editor/internal/api/client.js +14 -6
  7. package/dist/puck-editor/internal/api/client.js.map +1 -1
  8. package/dist/puck-editor/internal/api/create-puck-api.js +1 -1
  9. package/dist/puck-editor/internal/api/create-puck-api.js.map +1 -1
  10. package/dist/puck-editor/internal/api/handlers/template.d.ts +1 -1
  11. package/dist/puck-editor/internal/api/handlers/template.js +16 -4
  12. package/dist/puck-editor/internal/api/handlers/template.js.map +1 -1
  13. package/dist/puck-editor/internal/api/handlers/upload.js +6 -3
  14. package/dist/puck-editor/internal/api/handlers/upload.js.map +1 -1
  15. package/dist/puck-editor/internal/api/media-upload.d.ts +2 -2
  16. package/dist/puck-editor/internal/api/media-upload.js +6 -1
  17. package/dist/puck-editor/internal/api/media-upload.js.map +1 -1
  18. package/dist/puck-editor/internal/editor/puck-editor.js +2 -3
  19. package/dist/puck-editor/internal/editor/puck-editor.js.map +1 -1
  20. package/dist/puck-editor/internal/editor-config.d.ts +5 -2
  21. package/dist/puck-editor/internal/editor-config.js +32 -26
  22. package/dist/puck-editor/internal/editor-config.js.map +1 -1
  23. package/dist/puck-editor/internal/fields/link-picker/link-picker-control.js +323 -290
  24. package/dist/puck-editor/internal/fields/link-picker/link-picker-control.js.map +1 -1
  25. package/dist/puck-editor/internal/fields/media-selector/image-upload-form.js +3 -2
  26. package/dist/puck-editor/internal/fields/media-selector/image-upload-form.js.map +1 -1
  27. package/dist/puck-editor/internal/fields/media-selector/media-selector-field.js +3 -4
  28. package/dist/puck-editor/internal/fields/media-selector/media-selector-field.js.map +1 -1
  29. package/dist/puck-editor/internal/fields/media-selector/use-media-library.js +118 -101
  30. package/dist/puck-editor/internal/fields/media-selector/use-media-library.js.map +1 -1
  31. package/dist/puck-editor/internal/fields/media-selector/video-upload-form.js +3 -2
  32. package/dist/puck-editor/internal/fields/media-selector/video-upload-form.js.map +1 -1
  33. package/dist/puck-editor/internal/fields/node-selector/create-node-selector-field.d.ts +21 -13
  34. package/dist/puck-editor/internal/fields/node-selector/create-node-selector-field.js +9 -35
  35. package/dist/puck-editor/internal/fields/node-selector/create-node-selector-field.js.map +1 -1
  36. package/dist/puck-editor/internal/fields/node-selector/node-selector-field.d.ts +12 -0
  37. package/dist/puck-editor/internal/fields/node-selector/node-selector-field.js +56 -0
  38. package/dist/puck-editor/internal/fields/node-selector/node-selector-field.js.map +1 -0
  39. package/dist/puck-editor/internal/locale.d.ts +2 -6
  40. package/dist/puck-editor/internal/locale.js +6 -8
  41. package/dist/puck-editor/internal/locale.js.map +1 -1
  42. package/dist/puck-editor/internal/plugins/agent-plugin/agent-bridge.d.ts +1 -2
  43. package/dist/puck-editor/internal/plugins/agent-plugin/agent-bridge.js +4 -4
  44. package/dist/puck-editor/internal/plugins/agent-plugin/agent-bridge.js.map +1 -1
  45. package/dist/puck-editor/internal/plugins/agent-plugin/agent-plugin.d.ts +1 -2
  46. package/dist/puck-editor/internal/plugins/agent-plugin/agent-plugin.js +0 -2
  47. package/dist/puck-editor/internal/plugins/agent-plugin/agent-plugin.js.map +1 -1
  48. package/dist/puck-editor/internal/plugins/agent-plugin/templates.d.ts +2 -2
  49. package/dist/puck-editor/internal/plugins/agent-plugin/templates.js +7 -7
  50. package/dist/puck-editor/internal/plugins/agent-plugin/templates.js.map +1 -1
  51. package/dist/puck-editor/internal/plugins/templates-plugin/template-form.js +3 -1
  52. package/dist/puck-editor/internal/plugins/templates-plugin/template-form.js.map +1 -1
  53. package/dist/puck-editor/internal/plugins/templates-plugin/templates.d.ts +1 -1
  54. package/dist/puck-editor/internal/plugins/templates-plugin/templates.js +3 -3
  55. package/dist/puck-editor/internal/plugins/templates-plugin/templates.js.map +1 -1
  56. package/dist/puck-editor/internal/plugins/templates-plugin/use-template-dnd.js +32 -37
  57. package/dist/puck-editor/internal/plugins/templates-plugin/use-template-dnd.js.map +1 -1
  58. package/dist/puck-editor/internal/plugins/templates-plugin/use-templates.js +95 -72
  59. package/dist/puck-editor/internal/plugins/templates-plugin/use-templates.js.map +1 -1
  60. package/dist/puck-editor/internal/puck-wrapper.d.ts +1 -1
  61. package/dist/puck-editor/internal/puck-wrapper.js +89 -83
  62. package/dist/puck-editor/internal/puck-wrapper.js.map +1 -1
  63. package/dist/puck-editor/internal/use-puck-overlay.d.ts +3 -2
  64. package/dist/puck-editor/internal/use-puck-overlay.js +67 -56
  65. package/dist/puck-editor/internal/use-puck-overlay.js.map +1 -1
  66. package/package.json +1 -1
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import { createElement } from 'react';
4
+ import { AutoField } from '@puckeditor/core';
5
+ import { fetchNodeList } from "../../api/client.js";
6
+ import { usePuckContentLocale } from "../../editor-config.js";
7
+ export function NodeSelectorField({
8
+ options: {
9
+ nodeType,
10
+ label = 'Node',
11
+ placeholder = `Select ${nodeType}`,
12
+ showSearch = true,
13
+ initialQuery = '',
14
+ searchFields = ['title'],
15
+ fields,
16
+ getItemSummary,
17
+ mapRow,
18
+ mapProp
19
+ },
20
+ ...props
21
+ }) {
22
+ const contentLocale = usePuckContentLocale();
23
+ const external = {
24
+ type: 'external',
25
+ label: props.field.label ?? label,
26
+ placeholder,
27
+ showSearch,
28
+ initialQuery,
29
+ // Puck's external cache is not language-aware. Remount the picker on
30
+ // language changes and never reuse its unscoped request cache.
31
+ cache: {
32
+ enabled: false
33
+ },
34
+ fetchList: ({
35
+ query
36
+ }) => fetchNodeList(nodeType, {
37
+ lang: contentLocale,
38
+ query,
39
+ searchFields,
40
+ fields
41
+ }),
42
+ getItemSummary: item => {
43
+ if (getItemSummary) return getItemSummary(item);
44
+ const title = item?.title;
45
+ return typeof title === 'string' ? title : '';
46
+ },
47
+ mapRow,
48
+ mapProp
49
+ };
50
+ return /*#__PURE__*/createElement(AutoField, {
51
+ ...props,
52
+ key: contentLocale,
53
+ field: external
54
+ });
55
+ }
56
+ //# sourceMappingURL=node-selector-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-selector-field.js","names":["createElement","AutoField","fetchNodeList","usePuckContentLocale","NodeSelectorField","options","nodeType","label","placeholder","showSearch","initialQuery","searchFields","fields","getItemSummary","mapRow","mapProp","props","contentLocale","external","type","field","cache","enabled","fetchList","query","lang","item","title","key"],"sources":["../../../../../src/puck-editor/internal/fields/node-selector/node-selector-field.ts"],"sourcesContent":["'use client';\n\nimport { createElement } from 'react';\nimport {\n AutoField,\n type CustomFieldRender,\n type ExternalField,\n} from '@puckeditor/core';\n\nimport { fetchNodeList } from '../../api/client.ts';\nimport { usePuckContentLocale } from '../../editor-config.tsx';\nimport type {\n NodeSelectorFieldOptions,\n NodeSelectorItem,\n} from './create-node-selector-field.ts';\n\nexport function NodeSelectorField<TItem extends NodeSelectorItem>({\n options: {\n nodeType,\n label = 'Node',\n placeholder = `Select ${nodeType}`,\n showSearch = true,\n initialQuery = '',\n searchFields = ['title'],\n fields,\n getItemSummary,\n mapRow,\n mapProp,\n },\n ...props\n}: Parameters<CustomFieldRender<unknown>>[0] & {\n options: NodeSelectorFieldOptions<TItem>;\n}) {\n const contentLocale = usePuckContentLocale();\n const external: ExternalField<unknown> = {\n type: 'external',\n label: props.field.label ?? label,\n placeholder,\n showSearch,\n initialQuery,\n // Puck's external cache is not language-aware. Remount the picker on\n // language changes and never reuse its unscoped request cache.\n cache: { enabled: false },\n fetchList: ({ query }) =>\n fetchNodeList<TItem>(nodeType, {\n lang: contentLocale,\n query,\n searchFields,\n fields,\n }),\n getItemSummary: (item) => {\n if (getItemSummary) return getItemSummary(item as TItem);\n const title = (item as TItem)?.title;\n return typeof title === 'string' ? title : '';\n },\n mapRow,\n mapProp,\n };\n return createElement(AutoField, {\n ...props,\n key: contentLocale,\n field: external,\n });\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,OAAO;AACrC,SACEC,SAAS,QAGJ,kBAAkB;AAEzB,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,oBAAoB,QAAQ,wBAAyB;AAM9D,OAAO,SAASC,iBAAiBA,CAAiC;EAChEC,OAAO,EAAE;IACPC,QAAQ;IACRC,KAAK,GAAG,MAAM;IACdC,WAAW,GAAG,UAAUF,QAAQ,EAAE;IAClCG,UAAU,GAAG,IAAI;IACjBC,YAAY,GAAG,EAAE;IACjBC,YAAY,GAAG,CAAC,OAAO,CAAC;IACxBC,MAAM;IACNC,cAAc;IACdC,MAAM;IACNC;EACF,CAAC;EACD,GAAGC;AAGL,CAAC,EAAE;EACD,MAAMC,aAAa,GAAGd,oBAAoB,CAAC,CAAC;EAC5C,MAAMe,QAAgC,GAAG;IACvCC,IAAI,EAAE,UAAU;IAChBZ,KAAK,EAAES,KAAK,CAACI,KAAK,CAACb,KAAK,IAAIA,KAAK;IACjCC,WAAW;IACXC,UAAU;IACVC,YAAY;IACZ;IACA;IACAW,KAAK,EAAE;MAAEC,OAAO,EAAE;IAAM,CAAC;IACzBC,SAAS,EAAEA,CAAC;MAAEC;IAAM,CAAC,KACnBtB,aAAa,CAAQI,QAAQ,EAAE;MAC7BmB,IAAI,EAAER,aAAa;MACnBO,KAAK;MACLb,YAAY;MACZC;IACF,CAAC,CAAC;IACJC,cAAc,EAAGa,IAAI,IAAK;MACxB,IAAIb,cAAc,EAAE,OAAOA,cAAc,CAACa,IAAa,CAAC;MACxD,MAAMC,KAAK,GAAID,IAAI,EAAYC,KAAK;MACpC,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,EAAE;IAC/C,CAAC;IACDb,MAAM;IACNC;EACF,CAAC;EACD,oBAAOf,aAAa,CAACC,SAAS,EAAE;IAC9B,GAAGe,KAAK;IACRY,GAAG,EAAEX,aAAa;IAClBG,KAAK,EAAEF;EACT,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -4,9 +4,5 @@
4
4
  * rejects garbage (path/query smuggling into JSON:API URLs) rather than an
5
5
  * exact allow-list.
6
6
  */
7
- export declare function normalizeLang(value: string | undefined | null): string | undefined;
8
- /**
9
- * Locale from the first path segment. Editor surfaces only mount on localized
10
- * routes, so the segment is a locale in practice; falls back to English.
11
- */
12
- export declare function getPathLocale(pathname: string): string;
7
+ export declare function normalizeLang(value: unknown): string | undefined;
8
+ export declare function requireContentLocale(value: unknown): string;
@@ -7,14 +7,12 @@ const LOCALE_SEGMENT_RE = /^[a-z]{2,3}(-[a-zA-Z0-9]+)?$/;
7
7
  * exact allow-list.
8
8
  */
9
9
  export function normalizeLang(value) {
10
- return value != null && LOCALE_SEGMENT_RE.test(value) ? value : undefined;
10
+ return typeof value === 'string' && LOCALE_SEGMENT_RE.test(value) ? value : undefined;
11
11
  }
12
-
13
- /**
14
- * Locale from the first path segment. Editor surfaces only mount on localized
15
- * routes, so the segment is a locale in practice; falls back to English.
16
- */
17
- export function getPathLocale(pathname) {
18
- return normalizeLang(pathname.split('/')[1]) ?? 'en';
12
+ export function requireContentLocale(value) {
13
+ if (typeof value !== 'string' || !normalizeLang(value)) {
14
+ throw new Error('puck-editor: contentLocale is required and must be a valid language code (for example de, fr or de-CH); pass the content language explicitly, not the editor UI language.');
15
+ }
16
+ return value;
19
17
  }
20
18
  //# sourceMappingURL=locale.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"locale.js","names":["LOCALE_SEGMENT_RE","normalizeLang","value","test","undefined","getPathLocale","pathname","split"],"sources":["../../../src/puck-editor/internal/locale.ts"],"sourcesContent":["const LOCALE_SEGMENT_RE = /^[a-z]{2,3}(-[a-zA-Z0-9]+)?$/;\n\n/**\n * Keep a value only if it has locale shape, else drop it. Permissive by\n * design: the module does not know the project's configured locales, so it\n * rejects garbage (path/query smuggling into JSON:API URLs) rather than an\n * exact allow-list.\n */\nexport function normalizeLang(\n value: string | undefined | null\n): string | undefined {\n return value != null && LOCALE_SEGMENT_RE.test(value) ? value : undefined;\n}\n\n/**\n * Locale from the first path segment. Editor surfaces only mount on localized\n * routes, so the segment is a locale in practice; falls back to English.\n */\nexport function getPathLocale(pathname: string): string {\n return normalizeLang(pathname.split('/')[1]) ?? 'en';\n}\n"],"mappings":"AAAA,MAAMA,iBAAiB,GAAG,8BAA8B;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BC,KAAgC,EACZ;EACpB,OAAOA,KAAK,IAAI,IAAI,IAAIF,iBAAiB,CAACG,IAAI,CAACD,KAAK,CAAC,GAAGA,KAAK,GAAGE,SAAS;AAC3E;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,QAAgB,EAAU;EACtD,OAAOL,aAAa,CAACK,QAAQ,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI;AACtD","ignoreList":[]}
1
+ {"version":3,"file":"locale.js","names":["LOCALE_SEGMENT_RE","normalizeLang","value","test","undefined","requireContentLocale","Error"],"sources":["../../../src/puck-editor/internal/locale.ts"],"sourcesContent":["const LOCALE_SEGMENT_RE = /^[a-z]{2,3}(-[a-zA-Z0-9]+)?$/;\n\n/**\n * Keep a value only if it has locale shape, else drop it. Permissive by\n * design: the module does not know the project's configured locales, so it\n * rejects garbage (path/query smuggling into JSON:API URLs) rather than an\n * exact allow-list.\n */\nexport function normalizeLang(value: unknown): string | undefined {\n return typeof value === 'string' && LOCALE_SEGMENT_RE.test(value)\n ? value\n : undefined;\n}\n\nexport function requireContentLocale(value: unknown): string {\n if (typeof value !== 'string' || !normalizeLang(value)) {\n throw new Error(\n 'puck-editor: contentLocale is required and must be a valid language code (for example de, fr or de-CH); pass the content language explicitly, not the editor UI language.'\n );\n }\n return value;\n}\n"],"mappings":"AAAA,MAAMA,iBAAiB,GAAG,8BAA8B;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,KAAc,EAAsB;EAChE,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIF,iBAAiB,CAACG,IAAI,CAACD,KAAK,CAAC,GAC7DA,KAAK,GACLE,SAAS;AACf;AAEA,OAAO,SAASC,oBAAoBA,CAACH,KAAc,EAAU;EAC3D,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACD,aAAa,CAACC,KAAK,CAAC,EAAE;IACtD,MAAM,IAAII,KAAK,CACb,2KACF,CAAC;EACH;EACA,OAAOJ,KAAK;AACd","ignoreList":[]}
@@ -14,8 +14,7 @@ declare global {
14
14
  * Reads live appState/dispatch through a ref (updated every render) so the
15
15
  * exposed methods never close over a stale first-render dispatch.
16
16
  */
17
- export declare function AgentBridge({ config, lang, onSave, }: {
17
+ export declare function AgentBridge({ config, onSave, }: {
18
18
  config: Config;
19
- lang?: string;
20
19
  onSave?: PuckSaveHandler;
21
20
  }): null;
@@ -3,7 +3,7 @@
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { useEffect, useRef } from 'react';
5
5
  import { createUsePuck } from '@puckeditor/core';
6
- import { useBuiltinTemplates, usePuckContentModel, usePuckEditorConfig, usePuckPropTransforms } from "../../editor-config.js";
6
+ import { useBuiltinTemplates, usePuckContentLocale, usePuckContentModel, usePuckEditorConfig, usePuckPropTransforms } from "../../editor-config.js";
7
7
  import { applyPatchToPuck } from "./apply-patch-to-puck.js";
8
8
  import { describeComponent, listComponents } from "./catalog.js";
9
9
  import { PAGE_META_FIELDS } from "./constants.js";
@@ -26,9 +26,9 @@ export function AgentBridge(t0) {
26
26
  const $ = _c(24);
27
27
  const {
28
28
  config,
29
- lang,
30
29
  onSave
31
30
  } = t0;
31
+ const lang = usePuckContentLocale();
32
32
  const appState = usePuck(_temp);
33
33
  const dispatch = usePuck(_temp2);
34
34
  const {
@@ -119,8 +119,8 @@ export function AgentBridge(t0) {
119
119
  lang: get().lang,
120
120
  ...options
121
121
  }),
122
- listTemplates: () => listTemplates(get().templates, get().builtinTemplates),
123
- insertTemplate: (id, dest) => insertTemplate(get().dispatch, data(), get().config, get().templates, get().builtinTemplates, id, dest, get().propTransforms),
122
+ listTemplates: () => listTemplates(get().templates, get().builtinTemplates, get().lang),
123
+ insertTemplate: (id, dest) => insertTemplate(get().dispatch, data(), get().config, get().templates, get().builtinTemplates, id, get().lang, dest, get().propTransforms),
124
124
  addComponent: (type_1, options_0) => applyPatchToPuck(get().dispatch, data(), get().config, {
125
125
  action: "add",
126
126
  type: type_1,
@@ -1 +1 @@
1
- {"version":3,"file":"agent-bridge.js","names":["c","_c","useEffect","useRef","createUsePuck","useBuiltinTemplates","usePuckContentModel","usePuckEditorConfig","usePuckPropTransforms","applyPatchToPuck","describeComponent","listComponents","PAGE_META_FIELDS","listMedia","insertTemplate","listTemplates","uploadMedia","PAGE_META","Set","usePuck","AgentBridge","t0","$","config","lang","onSave","appState","_temp","dispatch","_temp2","templates","media","builtinTemplates","drupalBaseUrl","t1","undefined","propTransforms","t2","live","t3","current","t4","t5","Symbol","for","window","get","data","content","type","getPage","type_0","query","limit","offset","options","id","dest","addComponent","type_1","options_0","action","props","destinationId","destinationSlot","destinationIndex","updateComponent","id_0","newProps","removeComponent","id_1","setPageMeta","fields","clean","ignored","key","value","Object","entries","has","push","keys","length","ok","error","join","result","save","persist","console","info","puckAgent","assign","handle","key_0","s_0","s"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/agent-bridge.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { Config, createUsePuck, Data, PuckAction } from '@puckeditor/core';\n\nimport {\n useBuiltinTemplates,\n usePuckContentModel,\n usePuckEditorConfig,\n usePuckPropTransforms,\n} from '../../editor-config.tsx';\nimport { PuckSaveHandler } from '../../editor/save-guard.ts';\nimport { applyPatchToPuck } from './apply-patch-to-puck.ts';\nimport { describeComponent, listComponents } from './catalog.ts';\nimport { MediaType, PAGE_META_FIELDS } from './constants.ts';\nimport { listMedia } from './list-media.ts';\nimport {\n insertTemplate,\n listTemplates,\n TemplateDestination,\n} from './templates.ts';\nimport { uploadMedia } from './upload-media.ts';\n\ntype Dispatch = (action: PuckAction) => void;\n\ntype AddOptions = TemplateDestination & { props?: Record<string, unknown> };\n\nconst PAGE_META = new Set<string>(PAGE_META_FIELDS);\n\ndeclare global {\n interface Window {\n puckAgent?: Record<string, unknown>;\n }\n}\n\nconst usePuck = createUsePuck();\n\n/**\n * Mounts the mechanical `window.puckAgent` handle for a local agent driving the\n * editor via browser automation. Renders nothing. Only mounts inside the Puck\n * editor (already behind requireAuth). Edits are ephemeral dispatches until\n * save(), which persists through the same PATCH as the editor's Save button.\n *\n * Reads live appState/dispatch through a ref (updated every render) so the\n * exposed methods never close over a stale first-render dispatch.\n */\nexport function AgentBridge({\n config,\n lang,\n onSave,\n}: {\n config: Config;\n lang?: string;\n onSave?: PuckSaveHandler;\n}) {\n const appState = usePuck((s) => s.appState);\n const dispatch = usePuck((s) => s.dispatch) as Dispatch;\n const { templates, media } = usePuckContentModel();\n const builtinTemplates = useBuiltinTemplates();\n const { drupalBaseUrl = '' } = usePuckEditorConfig();\n const propTransforms = usePuckPropTransforms();\n\n const live = useRef({\n appState,\n dispatch,\n config,\n lang,\n onSave,\n templates,\n media,\n builtinTemplates,\n drupalBaseUrl,\n propTransforms,\n });\n useEffect(() => {\n live.current = {\n appState,\n dispatch,\n config,\n lang,\n onSave,\n templates,\n media,\n builtinTemplates,\n drupalBaseUrl,\n propTransforms,\n };\n });\n\n useEffect(() => {\n if (typeof window === 'undefined') return;\n\n const get = () => live.current;\n const data = () => get().appState?.data as Data | undefined;\n\n // Content methods, attached to the shared handle (lifecycle methods\n // open/close/isOpen/isReady are owned by PuckWrapper and stay mounted).\n const content = {\n // Palette (aus der Config: was kann ich einsetzen)\n listComponents: () => listComponents(get().config),\n describeComponent: (type: string) =>\n describeComponent(get().config, type),\n // Dokument (was ist gerade auf der Seite)\n getPage: () => data(),\n // Assets\n listMedia: (\n type: string,\n query?: string,\n limit?: number,\n offset?: number\n ) =>\n listMedia(\n get().lang,\n get().drupalBaseUrl,\n get().media,\n type,\n query,\n limit,\n offset\n ),\n uploadMedia: (options: {\n url: string;\n type?: MediaType;\n name?: string;\n alt?: string;\n }) => uploadMedia({ lang: get().lang, ...options }),\n // Templates\n listTemplates: () =>\n listTemplates(get().templates, get().builtinTemplates),\n insertTemplate: (id: string, dest?: TemplateDestination) =>\n insertTemplate(\n get().dispatch,\n data(),\n get().config,\n get().templates,\n get().builtinTemplates,\n id,\n dest,\n get().propTransforms\n ),\n // Writes (benannte Methoden, je ein Job)\n addComponent: (type: string, options?: AddOptions) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'add',\n type,\n props: options?.props,\n destinationId: options?.destinationId,\n destinationSlot: options?.destinationSlot,\n destinationIndex: options?.destinationIndex,\n }),\n updateComponent: (id: string, newProps: Record<string, unknown>) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'modify',\n id,\n newProps,\n }),\n removeComponent: (id: string) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'remove',\n id,\n }),\n setPageMeta: (fields: Record<string, unknown>) => {\n const clean: Record<string, unknown> = {};\n const ignored: string[] = [];\n for (const [key, value] of Object.entries(fields)) {\n if (PAGE_META.has(key)) {\n clean[key] = value;\n } else {\n ignored.push(key);\n }\n }\n if (!Object.keys(clean).length) {\n return {\n ok: false as const,\n error: `no known fields. Known: ${[...PAGE_META].join(', ')}`,\n };\n }\n const result = applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'setRoot',\n fields: clean,\n });\n return ignored.length && result.ok ? { ...result, ignored } : result;\n },\n // Persist — same human-gated PATCH as the editor's Save button.\n save: async () => {\n const persist = get().onSave;\n const current = data();\n if (!persist || !current) {\n return {\n ok: false as const,\n error: 'nothing to save: editor not ready',\n };\n }\n console.info('[puckAgent] save → publishing current page');\n return persist(current);\n },\n };\n\n window.puckAgent = Object.assign(window.puckAgent || {}, content);\n\n return () => {\n const handle = window.puckAgent;\n if (!handle) return;\n for (const key of Object.keys(content)) delete handle[key];\n };\n }, []);\n\n return null;\n}\n"],"mappings":"AAAA,YAAY;;AAAC,SAAAA,CAAA,IAAAC,EAAA;AAEb,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAAiBC,aAAa,QAA0B,kBAAkB;AAE1E,SACEC,mBAAmB,EACnBC,mBAAmB,EACnBC,mBAAmB,EACnBC,qBAAqB,QAChB,wBAAyB;AAEhC,SAASC,gBAAgB,QAAQ,0BAA0B;AAC3D,SAASC,iBAAiB,EAAEC,cAAc,QAAQ,cAAc;AAChE,SAAoBC,gBAAgB,QAAQ,gBAAgB;AAC5D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SACEC,cAAc,EACdC,aAAa,QAER,gBAAgB;AACvB,SAASC,WAAW,QAAQ,mBAAmB;AAM/C,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAASN,gBAAgB,CAAC;AAQnD,MAAMO,OAAO,GAAGf,aAAa,CAAC,CAAC;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAAgB,YAAAC,EAAA;EAAA,MAAAC,CAAA,GAAArB,EAAA;EAAqB;IAAAsB,MAAA;IAAAC,IAAA;IAAAC;EAAA,IAAAJ,EAQ3B;EACC,MAAAK,QAAA,GAAiBP,OAAO,CAACQ,KAAiB,CAAC;EAC3C,MAAAC,QAAA,GAAiBT,OAAO,CAACU,MAAiB,CAAC;EAC3C;IAAAC,SAAA;IAAAC;EAAA,IAA6BzB,mBAAmB,CAAC,CAAC;EAClD,MAAA0B,gBAAA,GAAyB3B,mBAAmB,CAAC,CAAC;EAC9C;IAAA4B,aAAA,EAAAC;EAAA,IAA+B3B,mBAAmB,CAAC,CAAC;EAA5C,MAAA0B,aAAA,GAAAC,EAAkB,KAAlBC,SAAkB,GAAlB,EAAkB,GAAlB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CAAC,GAA7DY,MAA6D;QAAA,CACrE;QAAAC,IAAA,EAEK,MAAAA,CAAA;UACJ,MAAAC,OAAA,GAAgB1C,GAAG,CAAC,CAAC,CAAArB,MAAO;UAC5B,MAAAe,OAAA,GAAgBO,IAAI,CAAC,CAAC;UACtB,IAAI,CAACyC,OAAmB,IAApB,CAAahD,OAAO;YAAA,OACf;cAAA2C,EAAA,EACD,KAAK;cAAAC,KAAA,EACF;YACT,CAAC;UAAA;UAEHK,OAAO,CAAAC,IAAK,CAAC,iDAA4C,CAAC;UAAA,OACnDF,OAAO,CAAChD,OAAO,CAAC;QAAA;MAE3B,CAAC;MAEDK,MAAM,CAAA8C,SAAA,GAAad,MAAM,CAAAe,MAAO,CAAC/C,MAAM,CAAA8C,SAAgB,IAAtB,CAAqB,CAAC,EAAE3C,OAAO,CAAhD;MAAA,OAET;QACL,MAAA6C,MAAA,GAAehD,MAAM,CAAA8C,SAAU;QAC/B,IAAI,CAACE,MAAM;UAAA;QAAA;QACX,KAAK,MAAAC,KAAS,IAAIjB,MAAM,CAAAI,IAAK,CAACjC,OAAO,CAAC;UAAE,OAAO6C,MAAM,CAAClB,KAAG,CAAC;QAAA;MAAC,CAC5D;IAAA,CACF;IAAEjC,EAAA,KAAE;IAAApB,CAAA,OAAAmB,EAAA;IAAAnB,CAAA,OAAAoB,EAAA;EAAA;IAAAD,EAAA,GAAAnB,CAAA;IAAAoB,EAAA,GAAApB,CAAA;EAAA;EApHLpB,SAAS,CAACuC,EAoHT,EAAEC,EAAE,CAAC;EAAA,OAEC,IAAI;AAAA;AAjKN,SAAAb,OAAAkE,GAAA;EAAA,OAU2BC,GAAC,CAAApE,QAAS;AAAA;AAVrC,SAAAD,MAAAqE,CAAA;EAAA,OAS2BA,CAAC,CAAAtE,QAAS;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"agent-bridge.js","names":["c","_c","useEffect","useRef","createUsePuck","useBuiltinTemplates","usePuckContentLocale","usePuckContentModel","usePuckEditorConfig","usePuckPropTransforms","applyPatchToPuck","describeComponent","listComponents","PAGE_META_FIELDS","listMedia","insertTemplate","listTemplates","uploadMedia","PAGE_META","Set","usePuck","AgentBridge","t0","$","config","onSave","lang","appState","_temp","dispatch","_temp2","templates","media","builtinTemplates","drupalBaseUrl","t1","undefined","propTransforms","t2","live","t3","current","t4","t5","Symbol","for","window","get","data","content","type","getPage","type_0","query","limit","offset","options","id","dest","addComponent","type_1","options_0","action","props","destinationId","destinationSlot","destinationIndex","updateComponent","id_0","newProps","removeComponent","id_1","setPageMeta","fields","clean","ignored","key","value","Object","entries","has","push","keys","length","ok","error","join","result","save","persist","console","info","puckAgent","assign","handle","key_0","s_0","s"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/agent-bridge.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { Config, createUsePuck, Data, PuckAction } from '@puckeditor/core';\n\nimport {\n useBuiltinTemplates,\n usePuckContentLocale,\n usePuckContentModel,\n usePuckEditorConfig,\n usePuckPropTransforms,\n} from '../../editor-config.tsx';\nimport { PuckSaveHandler } from '../../editor/save-guard.ts';\nimport { applyPatchToPuck } from './apply-patch-to-puck.ts';\nimport { describeComponent, listComponents } from './catalog.ts';\nimport { MediaType, PAGE_META_FIELDS } from './constants.ts';\nimport { listMedia } from './list-media.ts';\nimport {\n insertTemplate,\n listTemplates,\n TemplateDestination,\n} from './templates.ts';\nimport { uploadMedia } from './upload-media.ts';\n\ntype Dispatch = (action: PuckAction) => void;\n\ntype AddOptions = TemplateDestination & { props?: Record<string, unknown> };\n\nconst PAGE_META = new Set<string>(PAGE_META_FIELDS);\n\ndeclare global {\n interface Window {\n puckAgent?: Record<string, unknown>;\n }\n}\n\nconst usePuck = createUsePuck();\n\n/**\n * Mounts the mechanical `window.puckAgent` handle for a local agent driving the\n * editor via browser automation. Renders nothing. Only mounts inside the Puck\n * editor (already behind requireAuth). Edits are ephemeral dispatches until\n * save(), which persists through the same PATCH as the editor's Save button.\n *\n * Reads live appState/dispatch through a ref (updated every render) so the\n * exposed methods never close over a stale first-render dispatch.\n */\nexport function AgentBridge({\n config,\n onSave,\n}: {\n config: Config;\n onSave?: PuckSaveHandler;\n}) {\n const lang = usePuckContentLocale();\n const appState = usePuck((s) => s.appState);\n const dispatch = usePuck((s) => s.dispatch) as Dispatch;\n const { templates, media } = usePuckContentModel();\n const builtinTemplates = useBuiltinTemplates();\n const { drupalBaseUrl = '' } = usePuckEditorConfig();\n const propTransforms = usePuckPropTransforms();\n\n const live = useRef({\n appState,\n dispatch,\n config,\n lang,\n onSave,\n templates,\n media,\n builtinTemplates,\n drupalBaseUrl,\n propTransforms,\n });\n useEffect(() => {\n live.current = {\n appState,\n dispatch,\n config,\n lang,\n onSave,\n templates,\n media,\n builtinTemplates,\n drupalBaseUrl,\n propTransforms,\n };\n });\n\n useEffect(() => {\n if (typeof window === 'undefined') return;\n\n const get = () => live.current;\n const data = () => get().appState?.data as Data | undefined;\n\n // Content methods, attached to the shared handle (lifecycle methods\n // open/close/isOpen/isReady are owned by PuckWrapper and stay mounted).\n const content = {\n // Palette (aus der Config: was kann ich einsetzen)\n listComponents: () => listComponents(get().config),\n describeComponent: (type: string) =>\n describeComponent(get().config, type),\n // Dokument (was ist gerade auf der Seite)\n getPage: () => data(),\n // Assets\n listMedia: (\n type: string,\n query?: string,\n limit?: number,\n offset?: number\n ) =>\n listMedia(\n get().lang,\n get().drupalBaseUrl,\n get().media,\n type,\n query,\n limit,\n offset\n ),\n uploadMedia: (options: {\n url: string;\n type?: MediaType;\n name?: string;\n alt?: string;\n }) => uploadMedia({ lang: get().lang, ...options }),\n // Templates\n listTemplates: () =>\n listTemplates(get().templates, get().builtinTemplates, get().lang),\n insertTemplate: (id: string, dest?: TemplateDestination) =>\n insertTemplate(\n get().dispatch,\n data(),\n get().config,\n get().templates,\n get().builtinTemplates,\n id,\n get().lang,\n dest,\n get().propTransforms\n ),\n // Writes (benannte Methoden, je ein Job)\n addComponent: (type: string, options?: AddOptions) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'add',\n type,\n props: options?.props,\n destinationId: options?.destinationId,\n destinationSlot: options?.destinationSlot,\n destinationIndex: options?.destinationIndex,\n }),\n updateComponent: (id: string, newProps: Record<string, unknown>) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'modify',\n id,\n newProps,\n }),\n removeComponent: (id: string) =>\n applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'remove',\n id,\n }),\n setPageMeta: (fields: Record<string, unknown>) => {\n const clean: Record<string, unknown> = {};\n const ignored: string[] = [];\n for (const [key, value] of Object.entries(fields)) {\n if (PAGE_META.has(key)) {\n clean[key] = value;\n } else {\n ignored.push(key);\n }\n }\n if (!Object.keys(clean).length) {\n return {\n ok: false as const,\n error: `no known fields. Known: ${[...PAGE_META].join(', ')}`,\n };\n }\n const result = applyPatchToPuck(get().dispatch, data(), get().config, {\n action: 'setRoot',\n fields: clean,\n });\n return ignored.length && result.ok ? { ...result, ignored } : result;\n },\n // Persist — same human-gated PATCH as the editor's Save button.\n save: async () => {\n const persist = get().onSave;\n const current = data();\n if (!persist || !current) {\n return {\n ok: false as const,\n error: 'nothing to save: editor not ready',\n };\n }\n console.info('[puckAgent] save → publishing current page');\n return persist(current);\n },\n };\n\n window.puckAgent = Object.assign(window.puckAgent || {}, content);\n\n return () => {\n const handle = window.puckAgent;\n if (!handle) return;\n for (const key of Object.keys(content)) delete handle[key];\n };\n }, []);\n\n return null;\n}\n"],"mappings":"AAAA,YAAY;;AAAC,SAAAA,CAAA,IAAAC,EAAA;AAEb,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAAiBC,aAAa,QAA0B,kBAAkB;AAE1E,SACEC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB,EACnBC,qBAAqB,QAChB,wBAAyB;AAEhC,SAASC,gBAAgB,QAAQ,0BAA0B;AAC3D,SAASC,iBAAiB,EAAEC,cAAc,QAA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AC,iDAA4C,CAAC;UAAA,OACnDF,OAAO,CAAChD,OAAO,CAAC;QAAA;MAE3B,CAAC;MAEDK,MAAM,CAAA8C,SAAA,GAAad,MAAM,CAAAe,MAAO,CAAC/C,MAAM,CAAA8C,SAAgB,IAAtB,CAAqB,CAAC,EAAE3C,OAAO,CAAhD;MAAA,OAET;QACL,MAAA6C,MAAA,GAAehD,MAAM,CAAA8C,SAAU;QAC/B,IAAI,CAACE,MAAM;UAAA;QAAA;QACX,KAAK,MAAAC,KAAS,IAAIjB,MAAM,CAAAI,IAAK,CAACjC,OAAO,CAAC;UAAE,OAAO6C,MAAM,CAAClB,KAAG,CAAC;QAAA;MAAC,CAC5D;IAAA,CACF;IAAEjC,EAAA,KAAE;IAAApB,CAAA,OAAAmB,EAAA;IAAAnB,CAAA,OAAAoB,EAAA;EAAA;IAAAD,EAAA,GAAAnB,CAAA;IAAAoB,EAAA,GAAApB,CAAA;EAAA;EArHLrB,SAAS,CAACwC,EAqHT,EAAEC,EAAE,CAAC;EAAA,OAEC,IAAI;AAAA;AAjKN,SAAAb,OAAAkE,GAAA;EAAA,OAS2BC,GAAC,CAAApE,QAAS;AAAA;AATrC,SAAAD,MAAAqE,CAAA;EAAA,OAQ2BA,CAAC,CAAAtE,QAAS;AAAA","ignoreList":[]}
@@ -12,9 +12,8 @@ import { PuckSaveHandler } from '../../editor/save-guard.js';
12
12
  * createPage) live in useAgentHandle because open() must work before the editor
13
13
  * (and thus this plugin) mounts.
14
14
  */
15
- export declare function createAgentPlugin({ config, lang, onSave, label, }: {
15
+ export declare function createAgentPlugin({ config, onSave, label, }: {
16
16
  config: Config;
17
- lang?: string;
18
17
  onSave?: PuckSaveHandler;
19
18
  label?: string;
20
19
  }): Plugin;
@@ -19,7 +19,6 @@ import { AgentInfoPanel } from "./agent-info-panel.js";
19
19
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
20
20
  export function createAgentPlugin({
21
21
  config,
22
- lang,
23
22
  onSave,
24
23
  label
25
24
  }) {
@@ -36,7 +35,6 @@ export function createAgentPlugin({
36
35
  }) => /*#__PURE__*/_jsxs(_Fragment, {
37
36
  children: [children, /*#__PURE__*/_jsx(AgentBridge, {
38
37
  config: config,
39
- lang: lang,
40
38
  onSave: onSave
41
39
  })]
42
40
  })
@@ -1 +1 @@
1
- {"version":3,"file":"agent-plugin.js","names":["BotIcon","AgentBridge","AgentInfoPanel","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","createAgentPlugin","config","lang","onSave","label","name","icon","className","render","overrides","puck","children"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/agent-plugin.tsx"],"sourcesContent":["'use client';\n\nimport { Config, Plugin } from '@puckeditor/core';\nimport { BotIcon } from 'lucide-react';\n\nimport { PuckSaveHandler } from '../../editor/save-guard.ts';\nimport { AgentBridge } from './agent-bridge.tsx';\nimport { AgentInfoPanel } from './agent-info-panel.tsx';\n\n/**\n * Puck plugin that hosts the local-agent bridge. Always registered; the\n * wrapper-level handle (open/close/help via useAgentHandle) attaches for\n * logged-in editors, so `window.puckAgent` exists only during an editor session.\n *\n * The bridge mounts via the `puck` override (wraps the whole editor UI), so the\n * content methods are active whenever the plugin is installed — independent of\n * whether the Agent panel/tab is open. The `render` panel only shows the\n * copy-paste agent prompt. The lifecycle methods (open/close/isOpen/isReady/\n * createPage) live in useAgentHandle because open() must work before the editor\n * (and thus this plugin) mounts.\n */\nexport function createAgentPlugin({\n config,\n lang,\n onSave,\n label,\n}: {\n config: Config;\n lang?: string;\n onSave?: PuckSaveHandler;\n label?: string;\n}): Plugin {\n return {\n name: 'agent',\n label: label ?? 'Agent',\n icon: <BotIcon className=\"nh:size-6\" />,\n render: () => <AgentInfoPanel />,\n overrides: {\n puck: ({ children }) => (\n <>\n {children}\n <AgentBridge config={config} lang={lang} onSave={onSave} />\n </>\n ),\n },\n };\n}\n"],"mappings":"AAAA,YAAY;;AAGZ,SAASA,OAAO,QAAQ,cAAc;AAGtC,SAASC,WAAW,QAAQ,mBAAoB;AAChD,SAASC,cAAc,QAAQ,uBAAwB;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAYA,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,MAAM;EACNC,IAAI;EACJC,MAAM;EACNC;AAMF,CAAC,EAAU;EACT,OAAO;IACLC,IAAI,EAAE,OAAO;IACbD,KAAK,EAAEA,KAAK,IAAI,OAAO;IACvBE,IAAI,eAAEX,IAAA,CAACJ,OAAO;MAACgB,SAAS,EAAC;IAAW,CAAE,CAAC;IACvCC,MAAM,EAAEA,CAAA,kBAAMb,IAAA,CAACF,cAAc,IAAE,CAAC;IAChCgB,SAAS,EAAE;MACTC,IAAI,EAAEA,CAAC;QAAEC;MAAS,CAAC,kBACjBZ,KAAA,CAAAF,SAAA;QAAAc,QAAA,GACGA,QAAQ,eACThB,IAAA,CAACH,WAAW;UAACS,MAAM,EAAEA,MAAO;UAACC,IAAI,EAAEA,IAAK;UAACC,MAAM,EAAEA;QAAO,CAAE,CAAC;MAAA,CAC3D;IAEN;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"agent-plugin.js","names":["BotIcon","AgentBridge","AgentInfoPanel","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","createAgentPlugin","config","onSave","label","name","icon","className","render","overrides","puck","children"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/agent-plugin.tsx"],"sourcesContent":["'use client';\n\nimport { Config, Plugin } from '@puckeditor/core';\nimport { BotIcon } from 'lucide-react';\n\nimport { PuckSaveHandler } from '../../editor/save-guard.ts';\nimport { AgentBridge } from './agent-bridge.tsx';\nimport { AgentInfoPanel } from './agent-info-panel.tsx';\n\n/**\n * Puck plugin that hosts the local-agent bridge. Always registered; the\n * wrapper-level handle (open/close/help via useAgentHandle) attaches for\n * logged-in editors, so `window.puckAgent` exists only during an editor session.\n *\n * The bridge mounts via the `puck` override (wraps the whole editor UI), so the\n * content methods are active whenever the plugin is installed — independent of\n * whether the Agent panel/tab is open. The `render` panel only shows the\n * copy-paste agent prompt. The lifecycle methods (open/close/isOpen/isReady/\n * createPage) live in useAgentHandle because open() must work before the editor\n * (and thus this plugin) mounts.\n */\nexport function createAgentPlugin({\n config,\n onSave,\n label,\n}: {\n config: Config;\n onSave?: PuckSaveHandler;\n label?: string;\n}): Plugin {\n return {\n name: 'agent',\n label: label ?? 'Agent',\n icon: <BotIcon className=\"nh:size-6\" />,\n render: () => <AgentInfoPanel />,\n overrides: {\n puck: ({ children }) => (\n <>\n {children}\n <AgentBridge config={config} onSave={onSave} />\n </>\n ),\n },\n };\n}\n"],"mappings":"AAAA,YAAY;;AAGZ,SAASA,OAAO,QAAQ,cAAc;AAGtC,SAASC,WAAW,QAAQ,mBAAoB;AAChD,SAASC,cAAc,QAAQ,uBAAwB;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAYA,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,MAAM;EACNC,MAAM;EACNC;AAKF,CAAC,EAAU;EACT,OAAO;IACLC,IAAI,EAAE,OAAO;IACbD,KAAK,EAAEA,KAAK,IAAI,OAAO;IACvBE,IAAI,eAAEV,IAAA,CAACJ,OAAO;MAACe,SAAS,EAAC;IAAW,CAAE,CAAC;IACvCC,MAAM,EAAEA,CAAA,kBAAMZ,IAAA,CAACF,cAAc,IAAE,CAAC;IAChCe,SAAS,EAAE;MACTC,IAAI,EAAEA,CAAC;QAAEC;MAAS,CAAC,kBACjBX,KAAA,CAAAF,SAAA;QAAAa,QAAA,GACGA,QAAQ,eACTf,IAAA,CAACH,WAAW;UAACS,MAAM,EAAEA,MAAO;UAACC,MAAM,EAAEA;QAAO,CAAE,CAAC;MAAA,CAC/C;IAEN;EACF,CAAC;AACH","ignoreList":[]}
@@ -8,7 +8,7 @@ export type TemplateDestination = {
8
8
  destinationSlot?: string;
9
9
  destinationIndex?: number;
10
10
  };
11
- export declare function listTemplates(templatesConfig: PuckTemplatesConfig, builtins: BuiltinTemplate[]): Promise<{
11
+ export declare function listTemplates(templatesConfig: PuckTemplatesConfig, builtins: BuiltinTemplate[], contentLocale: string): Promise<{
12
12
  ai?: {
13
13
  instructions?: string | undefined;
14
14
  description?: string | undefined;
@@ -18,5 +18,5 @@ export declare function listTemplates(templatesConfig: PuckTemplatesConfig, buil
18
18
  category: import("../templates-plugin/templates.js").TemplateCategory;
19
19
  source: "custom" | "builtin";
20
20
  }[]>;
21
- export declare function insertTemplate(dispatch: Dispatch, data: Data | undefined, config: Config, templatesConfig: PuckTemplatesConfig, builtins: BuiltinTemplate[], templateId: string, dest?: TemplateDestination, propTransforms?: PuckPropTransforms): Promise<PatchResult>;
21
+ export declare function insertTemplate(dispatch: Dispatch, data: Data | undefined, config: Config, templatesConfig: PuckTemplatesConfig, builtins: BuiltinTemplate[], templateId: string, contentLocale: string, dest?: TemplateDestination, propTransforms?: PuckPropTransforms): Promise<PatchResult>;
22
22
  export {};
@@ -17,21 +17,21 @@ const summarize = template => ({
17
17
  }
18
18
  } : {})
19
19
  });
20
- async function resolveTemplates(templatesConfig, builtins) {
20
+ async function resolveTemplates(templatesConfig, builtins, contentLocale) {
21
21
  const {
22
22
  valid
23
23
  } = await getEditorQueryClient().fetchQuery({
24
- queryKey: [...TEMPLATES_QUERY_KEY],
25
- queryFn: () => fetchTemplates(templatesConfig)
24
+ queryKey: [...TEMPLATES_QUERY_KEY, contentLocale, templatesConfig],
25
+ queryFn: () => fetchTemplates(templatesConfig, contentLocale)
26
26
  });
27
27
  return mergeTemplates(builtins, valid);
28
28
  }
29
- export async function listTemplates(templatesConfig, builtins) {
30
- const templates = await resolveTemplates(templatesConfig, builtins);
29
+ export async function listTemplates(templatesConfig, builtins, contentLocale) {
30
+ const templates = await resolveTemplates(templatesConfig, builtins, contentLocale);
31
31
  return templates.map(summarize);
32
32
  }
33
- export async function insertTemplate(dispatch, data, config, templatesConfig, builtins, templateId, dest, propTransforms) {
34
- const templates = await resolveTemplates(templatesConfig, builtins);
33
+ export async function insertTemplate(dispatch, data, config, templatesConfig, builtins, templateId, contentLocale, dest, propTransforms) {
34
+ const templates = await resolveTemplates(templatesConfig, builtins, contentLocale);
35
35
  const template = templates.find(t => templateKey(t) === templateId);
36
36
  if (!template) {
37
37
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","names":["getEditorQueryClient","TEMPLATES_QUERY_KEY","expandTemplate","fetchTemplates","isRootLevelTemplate","mergeTemplates","templateKey","templateLabel","applyPatchToPuck","summarize","template","id","name","category","source","ai","description","instructions","resolveTemplates","templatesConfig","builtins","valid","fetchQuery","queryKey","queryFn","listTemplates","templates","map","insertTemplate","dispatch","data","config","templateId","dest","propTransforms","find","t","ok","error","destinationId","destinationSlot","targetsRoot","content","zone","undefined","action","components","destinationZone","destinationIndex"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/templates.ts"],"sourcesContent":["import type { Config, Data, PuckAction } from '@puckeditor/core';\n\nimport type {\n PuckPropTransforms,\n PuckTemplatesConfig,\n} from '../../content-model.ts';\nimport {\n getEditorQueryClient,\n TEMPLATES_QUERY_KEY,\n} from '../../editor-query-client.ts';\nimport {\n expandTemplate,\n fetchTemplates,\n isRootLevelTemplate,\n mergeTemplates,\n templateKey,\n templateLabel,\n type BuiltinTemplate,\n type Template,\n} from '../templates-plugin/templates.ts';\nimport { applyPatchToPuck, type PatchResult } from './apply-patch-to-puck.ts';\n\ntype Dispatch = (action: PuckAction) => void;\n\nexport type TemplateDestination = {\n destinationId?: string;\n destinationSlot?: string;\n destinationIndex?: number;\n};\n\nconst summarize = (template: Template) => ({\n id: templateKey(template),\n name: templateLabel(template, 'en'),\n category: template.category,\n source: template.source,\n ...(template.ai\n ? {\n ai: {\n ...(template.ai.description\n ? { description: template.ai.description }\n : {}),\n ...(template.ai.instructions\n ? { instructions: template.ai.instructions }\n : {}),\n },\n }\n : {}),\n});\n\nasync function resolveTemplates(\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[]\n): Promise<Template[]> {\n const { valid } = await getEditorQueryClient().fetchQuery({\n queryKey: [...TEMPLATES_QUERY_KEY],\n queryFn: () => fetchTemplates(templatesConfig),\n });\n return mergeTemplates(builtins, valid);\n}\n\nexport async function listTemplates(\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[]\n) {\n const templates = await resolveTemplates(templatesConfig, builtins);\n return templates.map(summarize);\n}\n\nexport async function insertTemplate(\n dispatch: Dispatch,\n data: Data | undefined,\n config: Config,\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[],\n templateId: string,\n dest?: TemplateDestination,\n propTransforms?: PuckPropTransforms\n): Promise<PatchResult> {\n const templates = await resolveTemplates(templatesConfig, builtins);\n const template = templates.find((t) => templateKey(t) === templateId);\n if (!template) {\n return { ok: false, error: `template \"${templateId}\" not found` };\n }\n if (dest?.destinationId && !dest.destinationSlot) {\n return {\n ok: false,\n error: 'destinationSlot is required with destinationId',\n };\n }\n\n const targetsRoot = !(dest?.destinationId && dest?.destinationSlot);\n if (template.category === 'block' && targetsRoot) {\n return {\n ok: false,\n error:\n 'block templates cannot be inserted at the page root; pass destinationId and destinationSlot',\n };\n }\n if (isRootLevelTemplate(template) && !targetsRoot) {\n return {\n ok: false,\n error: `${template.category} templates can only be inserted at the page root; omit destinationId and destinationSlot`,\n };\n }\n\n const { content } = expandTemplate(\n template,\n config,\n templateLabel(template, 'en'),\n propTransforms\n );\n const zone = dest?.destinationId\n ? `${dest.destinationId}:${dest.destinationSlot}`\n : undefined;\n\n return applyPatchToPuck(dispatch, data, config, {\n action: 'addMany',\n components: content,\n destinationZone: zone,\n destinationIndex: dest?.destinationIndex,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I,EAAEM,aAAa,GAC5B,GAAGN,IAAI,CAACM,aAAa,IAAIN,IAAI,CAACO,eAAe,EAAE,GAC/CI,SAAS;EAEb,OAAOpC,gBAAgB,CAACqB,QAAQ,EAAEC,IAAI,EAAEC,MAAM,EAAE;IAC9Cc,MAAM,EAAE,SAAS;IACjBC,UAAU,EAAEJ,OAAO;IACnBK,eAAe,EAAEJ,IAAI;IACrBK,gBAAgB,EAAEf,IAAI,EAAEe;EAC1B,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"templates.js","names":["getEditorQueryClient","TEMPLATES_QUERY_KEY","expandTemplate","fetchTemplates","isRootLevelTemplate","mergeTemplates","templateKey","templateLabel","applyPatchToPuck","summarize","template","id","name","category","source","ai","description","instructions","resolveTemplates","templatesConfig","builtins","contentLocale","valid","fetchQuery","queryKey","queryFn","listTemplates","templates","map","insertTemplate","dispatch","data","config","templateId","dest","propTransforms","find","t","ok","error","destinationId","destinationSlot","targetsRoot","content","zone","undefined","action","components","destinationZone","destinationIndex"],"sources":["../../../../../src/puck-editor/internal/plugins/agent-plugin/templates.ts"],"sourcesContent":["import type { Config, Data, PuckAction } from '@puckeditor/core';\n\nimport type {\n PuckPropTransforms,\n PuckTemplatesConfig,\n} from '../../content-model.ts';\nimport {\n getEditorQueryClient,\n TEMPLATES_QUERY_KEY,\n} from '../../editor-query-client.ts';\nimport {\n expandTemplate,\n fetchTemplates,\n isRootLevelTemplate,\n mergeTemplates,\n templateKey,\n templateLabel,\n type BuiltinTemplate,\n type Template,\n} from '../templates-plugin/templates.ts';\nimport { applyPatchToPuck, type PatchResult } from './apply-patch-to-puck.ts';\n\ntype Dispatch = (action: PuckAction) => void;\n\nexport type TemplateDestination = {\n destinationId?: string;\n destinationSlot?: string;\n destinationIndex?: number;\n};\n\nconst summarize = (template: Template) => ({\n id: templateKey(template),\n name: templateLabel(template, 'en'),\n category: template.category,\n source: template.source,\n ...(template.ai\n ? {\n ai: {\n ...(template.ai.description\n ? { description: template.ai.description }\n : {}),\n ...(template.ai.instructions\n ? { instructions: template.ai.instructions }\n : {}),\n },\n }\n : {}),\n});\n\nasync function resolveTemplates(\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[],\n contentLocale: string\n): Promise<Template[]> {\n const { valid } = await getEditorQueryClient().fetchQuery({\n queryKey: [...TEMPLATES_QUERY_KEY, contentLocale, templatesConfig],\n queryFn: () => fetchTemplates(templatesConfig, contentLocale),\n });\n return mergeTemplates(builtins, valid);\n}\n\nexport async function listTemplates(\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[],\n contentLocale: string\n) {\n const templates = await resolveTemplates(\n templatesConfig,\n builtins,\n contentLocale\n );\n return templates.map(summarize);\n}\n\nexport async function insertTemplate(\n dispatch: Dispatch,\n data: Data | undefined,\n config: Config,\n templatesConfig: PuckTemplatesConfig,\n builtins: BuiltinTemplate[],\n templateId: string,\n contentLocale: string,\n dest?: TemplateDestination,\n propTransforms?: PuckPropTransforms\n): Promise<PatchResult> {\n const templates = await resolveTemplates(\n templatesConfig,\n builtins,\n contentLocale\n );\n const template = templates.find((t) => templateKey(t) === templateId);\n if (!template) {\n return { ok: false, error: `template \"${templateId}\" not found` };\n }\n if (dest?.destinationId && !dest.destinationSlot) {\n return {\n ok: false,\n error: 'destinationSlot is required with destinationId',\n };\n }\n\n const targetsRoot = !(dest?.destinationId && dest?.destinationSlot);\n if (template.category === 'block' && targetsRoot) {\n return {\n ok: false,\n error:\n 'block templates cannot be inserted at the page root; pass destinationId and destinationSlot',\n };\n }\n if (isRootLevelTemplate(template) && !targetsRoot) {\n return {\n ok: false,\n error: `${template.category} templates can only be inserted at the page root; omit destinationId and destinationSlot`,\n };\n }\n\n const { content } = expandTemplate(\n template,\n config,\n templateLabel(template, 'en'),\n propTransforms\n );\n const zone = dest?.destinationId\n ? `${dest.destinationId}:${dest.destinationSlot}`\n : undefined;\n\n return applyPatchToPuck(dispatch, data, config, {\n action: 'addMany',\n components: content,\n destin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GAAGzC,cAAc,CAChCQ,QAAQ,EACRsB,MAAM,EACNzB,aAAa,CAACG,QAAQ,EAAE,IAAI,CAAC,EAC7ByB,cACF,CAAC;EACD,MAAMS,IAAI,GAAGV,IAAI,EAAEM,aAAa,GAC5B,GAAGN,IAAI,CAACM,aAAa,IAAIN,IAAI,CAACO,eAAe,EAAE,GAC/CI,SAAS;EAEb,OAAOrC,gBAAgB,CAACsB,QAAQ,EAAEC,IAAI,EAAEC,MAAM,EAAE;IAC9Cc,MAAM,EAAE,SAAS;IACjBC,UAAU,EAAEJ,OAAO;IACnBK,eAAe,EAAEJ,IAAI;IACrBK,gBAAgB,EAAEf,IAAI,EAAEe;EAC1B,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -5,6 +5,7 @@ import { Button } from '@puckeditor/core';
5
5
  import { toast } from 'sonner';
6
6
  import { saveTemplate } from "../../api/client.js";
7
7
  import { localizeApiMessage } from "../../api/localize-message.js";
8
+ import { usePuckContentLocale } from "../../editor-config.js";
8
9
  import { usePuckDictionary } from "../../i18n.js";
9
10
  import { AiOptionsFields } from "./ai-options-fields.js";
10
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -15,6 +16,7 @@ export function TemplateForm({
15
16
  category
16
17
  }) {
17
18
  const dict = usePuckDictionary();
19
+ const contentLocale = usePuckContentLocale();
18
20
  const t = dict.templates;
19
21
  const [isPending, setIsPending] = useState(false);
20
22
  const [errorMessage, setErrorMessage] = useState('');
@@ -28,7 +30,7 @@ export function TemplateForm({
28
30
  const formData = new FormData(formElement);
29
31
  formData.append('content', JSON.stringify(content));
30
32
  formData.append('category', category);
31
- const result = await saveTemplate(formData);
33
+ const result = await saveTemplate(formData, contentLocale);
32
34
  if (!result.success) {
33
35
  setErrorMessage(localizeApiMessage(dict, result) || t.saveFailed);
34
36
  toast.error(t.saveFailed);
@@ -1 +1 @@
1
- {"version":3,"file":"template-form.js","names":["useState","Button","toast","saveTemplate","localizeApiMessage","usePuckDictionary","AiOptionsFields","jsx","_jsx","jsxs","_jsxs","TemplateForm","content","onTemplateSaved","onCancel","category","dict","t","templates","isPending","setIsPending","errorMessage","setErrorMessage","scopeLabel","scopePage","scopeSection","handleSubmit","e","preventDefault","formElement","currentTarget","formData","FormData","append","JSON","stringify","result","success","saveFailed","error","console","message","saved","reset","onSubmit","className","children","htmlFor","name","type","id","required","savedAsLabel","variant","onClick","cancel","disabled","stopPropagation","saving","save"],"sources":["../../../../../src/puck-editor/internal/plugins/templates-plugin/template-form.tsx"],"sourcesContent":["'use client';\n\nimport { FormEvent, useState } from 'react';\nimport { Button, Content } from '@puckeditor/core';\nimport { toast } from 'sonner';\n\nimport { saveTemplate } from '../../api/client.ts';\nimport { localizeApiMessage } from '../../api/localize-message.ts';\nimport { usePuckDictionary } from '../../i18n.tsx';\nimport { AiOptionsFields } from './ai-options-fields.tsx';\nimport type { TemplateCategory } from './templates.ts';\n\ninterface TemplateFormProps {\n content: Content;\n onCancel?: () => void;\n onTemplateSaved?: () => void;\n category: TemplateCategory;\n}\n\nexport function TemplateForm({\n content,\n onTemplateSaved,\n onCancel,\n category,\n}: TemplateFormProps) {\n const dict = usePuckDictionary();\n const t = dict.templates;\n const [isPending, setIsPending] = useState(false);\n const [errorMessage, setErrorMessage] = useState('');\n\n const scopeLabel = category === 'page' ? t.scopePage : t.scopeSection;\n\n const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n setIsPending(true);\n setErrorMessage('');\n\n try {\n const formElement = e.currentTarget;\n const formData = new FormData(formElement);\n formData.append('content', JSON.stringify(content));\n formData.append('category', category);\n\n const result = await saveTemplate(formData);\n\n if (!result.success) {\n setErrorMessage(localizeApiMessage(dict, result) || t.saveFailed);\n toast.error(t.saveFailed);\n console.error('Failed to save template:', result.message);\n setIsPending(false);\n return;\n }\n\n toast.success(t.saved);\n formElement.reset();\n if (onTemplateSaved) {\n onTemplateSaved();\n }\n } catch (error) {\n setErrorMessage(t.saveFailed);\n toast.error(t.saveFailed);\n console.error('Failed to save template:', error);\n }\n\n setIsPending(false);\n };\n\n return (\n <form onSubmit={handleSubmit} className=\"nh:space-y-4\">\n {errorMessage && (\n <div className=\"nh:rounded nh:border nh:border-red-200 nh:bg-red-100 nh:p-2 nh:text-sm nh:font-medium text-red-700\">\n {errorMessage}\n </div>\n )}\n\n <div>\n <label\n htmlFor=\"name\"\n className=\"nh:block nh:text-sm nh:font-medium nh:text-gray-700\"\n >\n {t.name}\n </label>\n <input\n type=\"text\"\n id=\"name\"\n name=\"name\"\n className=\"nh:mt-1 nh:block nh:w-full nh:max-w-3xl nh:rounded-md nh:border-gray-300 nh:shadow-sm\"\n required\n />\n </div>\n\n <AiOptionsFields />\n\n <p className=\"nh:text-sm nh:text-gray-500\">\n {t.savedAsLabel} <span className=\"nh:font-medium\">{scopeLabel}</span>\n </p>\n\n <div className=\"nh:mt-6 nh:flex nh:justify-between nh:gap-2\">\n <Button type=\"button\" variant=\"secondary\" onClick={onCancel}>\n {t.cancel}\n </Button>\n <Button\n type=\"submit\"\n disabled={isPending}\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n {isPending ? t.saving : t.save}\n </Button>\n </div>\n </form>\n );\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAAoBA,QAAQ,QAAQ,OAAO;AAC3C,SAASC,MAAM,QAAiB,kBAAkB;AAClD,SAASC,KAAK,QAAQ,QAAQ;AAE9B,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,iBAAiB,QAAQ,eAAgB;AAClD,SAASC,eAAe,QAAQ,wBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAU1D,OAAO,SAASC,YAAYA,CAAC;EAC3BC,OAAO;EACPC,eAAe;EACfC,QAAQ;EACRC;AACiB,CAAC,EAAE;EACpB,MAAMC,IAAI,GAAGX,iBAAiB,CAAC,CAAC;EAChC,MAAMY,CAAC,GAA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O,QAAQ,EAAErC,SAAU;QACpBmC,OAAO,EAAG3B,GAAC,IAAK;UACdA,GAAC,CAAC8B,eAAe,CAAC,CAAC;QACrB,CAAE;QAAAX,QAAA,EAED3B,SAAS,GAAGF,CAAC,CAACyC,MAAM,GAAGzC,CAAC,CAAC0C;MAAI,CACxB,CAAC;IAAA,CACN,CAAC;EAAA,CACF,CAAC;AAEX","ignoreList":[]}
1
+ {"version":3,"file":"template-form.js","names":["useState","Button","toast","saveTemplate","localizeApiMessage","usePuckContentLocale","usePuckDictionary","AiOptionsFields","jsx","_jsx","jsxs","_jsxs","TemplateForm","content","onTemplateSaved","onCancel","category","dict","contentLocale","t","templates","isPending","setIsPending","errorMessage","setErrorMessage","scopeLabel","scopePage","scopeSection","handleSubmit","e","preventDefault","formElement","currentTarget","formData","FormData","append","JSON","stringify","result","success","saveFailed","error","console","message","saved","reset","onSubmit","className","children","htmlFor","name","type","id","required","savedAsLabel","variant","onClick","cancel","disabled","stopPropagation","saving","save"],"sources":["../../../../../src/puck-editor/internal/plugins/templates-plugin/template-form.tsx"],"sourcesContent":["'use client';\n\nimport { FormEvent, useState } from 'react';\nimport { Button, Content } from '@puckeditor/core';\nimport { toast } from 'sonner';\n\nimport { saveTemplate } from '../../api/client.ts';\nimport { localizeApiMessage } from '../../api/localize-message.ts';\nimport { usePuckContentLocale } from '../../editor-config.tsx';\nimport { usePuckDictionary } from '../../i18n.tsx';\nimport { AiOptionsFields } from './ai-options-fields.tsx';\nimport type { TemplateCategory } from './templates.ts';\n\ninterface TemplateFormProps {\n content: Content;\n onCancel?: () => void;\n onTemplateSaved?: () => void;\n category: TemplateCategory;\n}\n\nexport function TemplateForm({\n content,\n onTemplateSaved,\n onCancel,\n category,\n}: TemplateFormProps) {\n const dict = usePuckDictionary();\n const contentLocale = usePuckContentLocale();\n const t = dict.templates;\n const [isPending, setIsPending] = useState(false);\n const [errorMessage, setErrorMessage] = useState('');\n\n const scopeLabel = category === 'page' ? t.scopePage : t.scopeSection;\n\n const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n setIsPending(true);\n setErrorMessage('');\n\n try {\n const formElement = e.currentTarget;\n const formData = new FormData(formElement);\n formData.append('content', JSON.stringify(content));\n formData.append('category', category);\n\n const result = await saveTemplate(formData, contentLocale);\n\n if (!result.success) {\n setErrorMessage(localizeApiMessage(dict, result) || t.saveFailed);\n toast.error(t.saveFailed);\n console.error('Failed to save template:', result.message);\n setIsPending(false);\n return;\n }\n\n toast.success(t.saved);\n formElement.reset();\n if (onTemplateSaved) {\n onTemplateSaved();\n }\n } catch (error) {\n setErrorMessage(t.saveFailed);\n toast.error(t.saveFailed);\n console.error('Failed to save template:', error);\n }\n\n setIsPending(false);\n };\n\n return (\n <form onSubmit={handleSubmit} className=\"nh:space-y-4\">\n {errorMessage && (\n <div className=\"nh:rounded nh:border nh:border-red-200 nh:bg-red-100 nh:p-2 nh:text-sm nh:font-medium text-red-700\">\n {errorMessage}\n </div>\n )}\n\n <div>\n <label\n htmlFor=\"name\"\n className=\"nh:block nh:text-sm nh:font-medium nh:text-gray-700\"\n >\n {t.name}\n </label>\n <input\n type=\"text\"\n id=\"name\"\n name=\"name\"\n className=\"nh:mt-1 nh:block nh:w-full nh:max-w-3xl nh:rounded-md nh:border-gray-300 nh:shadow-sm\"\n required\n />\n </div>\n\n <AiOptionsFields />\n\n <p className=\"nh:text-sm nh:text-gray-500\">\n {t.savedAsLabel} <span className=\"nh:font-medium\">{scopeLabel}</span>\n </p>\n\n <div className=\"nh:mt-6 nh:flex nh:justify-between nh:gap-2\">\n <Button type=\"button\" variant=\"secondary\" onClick={onCancel}>\n {t.cancel}\n </Button>\n <Button\n type=\"submit\"\n disabled={isPending}\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n {isPending ? t.saving : t.save}\n </Button>\n </div>\n </form>\n );\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAAoBA,QAAQ,QAAQ,OAAO;AAC3C,SAASC,MAAM,QAAiB,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C,eAEN5C,IAAA,CAACF,eAAe,IAAE,CAAC,eAEnBI,KAAA;MAAGoC,SAAS,EAAC,6BAA6B;MAAAC,QAAA,GACvC7B,CAAC,CAACmC,YAAY,EAAC,GAAC,eAAA7C,IAAA;QAAMsC,SAAS,EAAC,gBAAgB;QAAAC,QAAA,EAAEvB;MAAU,CAAO,CAAC;IAAA,CACpE,CAAC,eAEJd,KAAA;MAAKoC,SAAS,EAAC,6CAA6C;MAAAC,QAAA,gBAC1DvC,IAAA,CAACR,MAAM;QAACkD,IAAI,EAAC,QAAQ;QAACI,OAAO,EAAC,WAAW;QAACC,OAAO,EAAEzC,QAAS;QAAAiC,QAAA,EACzD7B,CAAC,CAACsC;MAAM,CACH,CAAC,eACThD,IAAA,CAACR,MAAM;QACLkD,IAAI,EAAC,QAAQ;QACbO,QAAQ,EAAErC,SAAU;QACpBmC,OAAO,EAAG3B,GAAC,IAAK;UACdA,GAAC,CAAC8B,eAAe,CAAC,CAAC;QACrB,CAAE;QAAAX,QAAA,EAED3B,SAAS,GAAGF,CAAC,CAACyC,MAAM,GAAGzC,CAAC,CAAC0C;MAAI,CACxB,CAAC;IAAA,CACN,CAAC;EAAA,CACF,CAAC;AAEX","ignoreList":[]}
@@ -35,7 +35,7 @@ export declare const templateMatchesQuery: (template: Template, locale: string,
35
35
  export declare const asBuiltinTemplates: (builtins: BuiltinTemplate[]) => Template[];
36
36
  export declare const mergeTemplates: (builtins: BuiltinTemplate[], custom: Template[]) => Template[];
37
37
  export declare const isBrokenTemplate: (template: Template | BrokenTemplate) => template is BrokenTemplate;
38
- export declare const fetchTemplates: (config: PuckTemplatesConfig) => Promise<FetchedTemplates>;
38
+ export declare const fetchTemplates: (config: PuckTemplatesConfig, contentLocale: string) => Promise<FetchedTemplates>;
39
39
  export declare const expandTemplate: (template: Template, config: Config, outlineLabel?: string, propTransforms?: PuckPropTransforms) => {
40
40
  content: ComponentData[];
41
41
  skipped: number;
@@ -1,7 +1,7 @@
1
1
  import { walkTree } from '@puckeditor/core';
2
2
  import { puckFetch } from "../../api/client.js";
3
3
  import { applyPropTransforms } from "../../content-model.js";
4
- import { getPathLocale } from "../../locale.js";
4
+ import { requireContentLocale } from "../../locale.js";
5
5
  import { generateId } from "../../utils.js";
6
6
  import { ICON_PROP, NAME_PROP } from "../outline-plugin/outline-tree.js";
7
7
  const asString = value => typeof value === 'string' && value ? value : undefined;
@@ -58,8 +58,8 @@ const mapFragment = (raw, config) => {
58
58
  data
59
59
  };
60
60
  };
61
- export const fetchTemplates = async config => {
62
- const language = getPathLocale(window.location.pathname);
61
+ export const fetchTemplates = async (config, contentLocale) => {
62
+ const language = requireContentLocale(contentLocale);
63
63
  const {
64
64
  data
65
65
  } = await puckFetch(`/fragment/${config.fragmentType}?lang=${language}&limit=100`);
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","names":["walkTree","puckFetch","applyPropTransforms","getPathLocale","generateId","ICON_PROP","NAME_PROP","asString","value","undefined","parseCategory","templateKey","template","source","id","isRootLevelTemplate","category","templateLabel","locale","name","split","en","Object","values","templateMatchesQuery","query","toLowerCase","includes","trim","asBuiltinTemplates","builtins","map","mergeTemplates","custom","isBrokenTemplate","mapFragment","raw","config","broken","title","data","parsed","JSON","parse","String","dataField","Array","isArray","console","warn","categoryField","description","aiDescriptionField","instructions","aiInstructionsField","ai","fetchTemplates","language","window","location","pathname","fragmentType","valid","mapped","push","expandTemplate","outlineLabel","propTransforms","root","props","content","zones","skipped","expanded","filter","component","known","Boolean","components","type","defaultProps","length","icon"],"sources":["../../../../../src/puck-editor/internal/plugins/templates-plugin/templates.ts"],"sourcesContent":["import { walkTree } from '@puckeditor/core';\nimport type { ComponentData, Config } from '@puckeditor/core';\n\nimport { puckFetch } from '../../api/client.ts';\nimport {\n applyPropTransforms,\n type PuckPropTransforms,\n type PuckTemplatesConfig,\n} from '../../content-model.ts';\nimport { getPathLocale } from '../../locale.ts';\nimport { generateId } from '../../utils.ts';\nimport { ICON_PROP, NAME_PROP } from '../outline-plugin/outline-tree.ts';\n\nexport type TemplateCategory = 'page' | 'section' | 'block';\n\nexport type TemplateAi = {\n description?: string;\n instructions?: string;\n};\n\nexport type TemplateEnvelope = {\n id: string;\n name: string | Record<string, string>;\n category: TemplateCategory;\n icon?: string;\n ai?: TemplateAi;\n group?: string;\n data: ComponentData[];\n};\n\nexport type BuiltinTemplate = TemplateEnvelope;\n\nexport type Template = TemplateEnvelope & {\n source: 'builtin' | 'custom';\n};\n\nexport type BrokenTemplate = {\n source: 'custom';\n broken: true;\n id: string;\n name: string;\n};\n\nexport type FetchedTemplates = {\n valid: Template[];\n broken: BrokenTemplate[];\n};\n\ntype RawFragment = { id: string; title: string } & Record<string, unknown>;\n\nconst asString = (value: unknown): string | undefined =>\n typeof value === 'string' && value ? value : undefined;\n\nconst parseCategory = (value: unknown): TemplateCategory | null =>\n value === 'page' || value === 'section' || value === 'block' ? value : null;\n\nexport const templateKey = (template: Template): string =>\n template.source === 'custom' ? template.id : `builtin-${template.id}`;\n\nexport const isRootLevelTemplate = (\n template: Template | BuiltinTemplate\n): boolean => template.category === 'section' || template.category === 'page';\n\nexport const templateLabel = (\n template: Template | BuiltinTemplate,\n locale: string\n): string => {\n const name = template.name;\n if (typeof name === 'string') return name;\n if (!name) return '';\n return (\n name[locale] ??\n name[locale.split('-')[0]] ??\n name.en ??\n Object.values(name)[0] ??\n ''\n );\n};\n\nexport const templateMatchesQuery = (\n template: Template,\n locale: string,\n query: string\n): boolean =>\n templateLabel(template, locale)\n .toLowerCase()\n .includes(query.trim().toLowerCase());\n\nexport const asBuiltinTemplates = (builtins: BuiltinTemplate[]): Template[] =>\n builtins.map((template) => ({ ...template, source: 'builtin' as const }));\n\nexport const mergeTemplates = (\n builtins: BuiltinTemplate[],\n custom: Template[]\n): Template[] => [...asBuiltinTemplates(builtins), ...custom];\n\nexport const isBrokenTemplate = (\n template: Template | BrokenTemplate\n): template is BrokenTemplate => 'broken' in template;\n\nconst mapFragment = (\n raw: RawFragment,\n config: PuckTemplatesConfig\n): Template | BrokenTemplate => {\n const broken = (): BrokenTemplate => ({\n source: 'custom',\n broken: true,\n id: raw.id,\n name: raw.title,\n });\n\n let data: ComponentData[];\n try {\n const parsed = JSON.parse(String(raw[config.dataField] ?? ''));\n data = Array.isArray(parsed) ? parsed : [parsed];\n } catch {\n console.warn(\n `puck-editor: template fragment \"${raw.id}\" has unparseable data`\n );\n return broken();\n }\n\n const category = parseCategory(raw[config.categoryField]);\n if (!category) {\n console.warn(\n `puck-editor: template fragment \"${raw.id}\" has an invalid category`\n );\n return broken();\n }\n\n const description = asString(raw[config.aiDescriptionField]);\n const instructions = asString(raw[config.aiInstructionsField]);\n const ai =\n description || instructions ? { description, instructions } : undefined;\n\n return {\n source: 'custom',\n id: raw.id,\n name: asString(raw.title) ?? raw.id,\n category,\n ...(ai ? { ai } : {}),\n data,\n };\n};\n\nexport const fetchTemplates = async (\n config: PuckTemplatesConfig\n): Promise<FetchedTemplates> => {\n const language = getPathLocale(window.location.pathname);\n const { data } = await puckFetch<{ data: RawFragment[] }>(\n `/fragment/${config.fragmentType}?lang=${language}&limit=100`\n );\n const valid: Template[] = [];\n const broken: BrokenTemplate[] = [];\n for (const raw of data) {\n const mapped = mapFragment(raw, config);\n if (isBrokenTemplate(mapped)) broken.push(mapped);\n else valid.push(mapped);\n }\n return { valid, broken };\n};\n\nexport const expandTemplate = (\n template: Template,\n config: Config,\n outlineLabel?: string,\n propTransforms?: PuckPropTransforms\n): { content: ComponentData[]; skipped: number } => {\n const raw = applyPropTransforms(\n { root: { props: {} }, content: template.data, zones: {} },\n propTransforms,\n config,\n `template \"${template.id}\"`\n ).content as ComponentData[];\n\n let skipped = 0;\n const expanded = walkTree(\n { root: { props: {} }, content: raw, zones: {} },\n config,\n (content) =>\n content\n .filter((component) => {\n const known = Boolean(config.components[component.type]);\n if (!known) skipped++;\n return known;\n })\n .map((component) => ({\n ...component,\n props: {\n ...config.components[component.type]?.defaultProps,\n ...component.props,\n id: generateId(component.type),\n },\n }))\n );\n\n const content = expanded.content;\n if (\n outlineLabel &&\n template.category !== 'page' &&\n template.data.length === 1 &&\n content.length === 1\n ) {\n content[0] = {\n ...content[0],\n props: {\n ...content[0].props,\n [NAME_PROP]: outlineLabel,\n ...(template.icon ? { [ICON_PROP]: template.icon } : {}),\n },\n };\n }\n return { content, skipped };\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAG3C,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SACEC,mBAAmB,QAGd,wBAAwB;AAC/B,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,SAAS,EAAEC,SAAS,QAAQ,mCAAmC;AAuCxE,MAAMC,QAAQ,GAAIC,KAAc,IAC9B,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,GAAGA,KAAK,GAAGC,SAAS;AAExD,MAAMC,aAAa,GAAIF,KAAc,IACnCA,KAAK,KAAK,MAAM,IAAIA,KAAK,KAAK,SAAS,IAAIA,KAAK,KAAK,OAAO,GAAGA,KAAK,GAAG,IAAI;AAE7E,OAAO,MAAMG,WAAW,GAAIC,QAAkB,IAC5CA,QAAQ,CAACC,MAAM,KAAK,QAAQ,GAAGD,QAAQ,CAACE,EAAE,GAAG,WAAWF,QAAQ,CAACE,EAAE,EAAE;AAEvE,OAAO,MAAMC,mBAAmB,GAC9BH,QAAoC,IACxBA,QAAQ,CAACI,QAAQ,KAAK,SAAS,IAAIJ,QAAQ,CAACI,QAAQ,KAAK,MAAM;AAE7E,OAAO,MAAMC,aAAa,GAAGA,CAC3BL,QAAoC,EACpCM,MAAc,KACH;EACX,MAAMC,IAAI,GAAGP,QAAQ,CAACO,IAAI;EAC1B,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE,OAAOA,IAAI;EACzC,IAAI,CAACA,IAAI,EAAE,OAAO,EAAE;EACpB,OACEA,IAAI,CAACD,MAAM,CAAC,IACZC,IAAI,CAACD,M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GAAGhC,MAAM,CAACyC,UAAU,CAACH,SAAS,CAACI,IAAI,CAAC,EAAEC,YAAY;MAClD,GAAGL,SAAS,CAACN,KAAK;MAClBvD,EAAE,EAAEV,UAAU,CAACuE,SAAS,CAACI,IAAI;IAC/B;EACF,CAAC,CAAC,CACR,CAAC;EAED,MAAMT,OAAO,GAAGG,QAAQ,CAACH,OAAO;EAChC,IACEJ,YAAY,IACZtD,QAAQ,CAACI,QAAQ,KAAK,MAAM,IAC5BJ,QAAQ,CAAC4B,IAAI,CAACyC,MAAM,KAAK,CAAC,IAC1BX,OAAO,CAACW,MAAM,KAAK,CAAC,EACpB;IACAX,OAAO,CAAC,CAAC,CAAC,GAAG;MACX,GAAGA,OAAO,CAAC,CAAC,CAAC;MACbD,KAAK,EAAE;QACL,GAAGC,OAAO,CAAC,CAAC,CAAC,CAACD,KAAK;QACnB,CAAC/D,SAAS,GAAG4D,YAAY;QACzB,IAAItD,QAAQ,CAACsE,IAAI,GAAG;UAAE,CAAC7E,SAAS,GAAGO,QAAQ,CAACsE;QAAK,CAAC,GAAG,CAAC,CAAC;MACzD;IACF,CAAC;EACH;EACA,OAAO;IAAEZ,OAAO;IAAEE;EAAQ,CAAC;AAC7B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"templates.js","names":["walkTree","puckFetch","applyPropTransforms","requireContentLocale","generateId","ICON_PROP","NAME_PROP","asString","value","undefined","parseCategory","templateKey","template","source","id","isRootLevelTemplate","category","templateLabel","locale","name","split","en","Object","values","templateMatchesQuery","query","toLowerCase","includes","trim","asBuiltinTemplates","builtins","map","mergeTemplates","custom","isBrokenTemplate","mapFragment","raw","config","broken","title","data","parsed","JSON","parse","String","dataField","Array","isArray","console","warn","categoryField","description","aiDescriptionField","instructions","aiInstructionsField","ai","fetchTemplates","contentLocale","language","fragmentType","valid","mapped","push","expandTemplate","outlineLabel","propTransforms","root","props","content","zones","skipped","expanded","filter","component","known","Boolean","components","type","defaultProps","length","icon"],"sources":["../../../../../src/puck-editor/internal/plugins/templates-plugin/templates.ts"],"sourcesContent":["import { walkTree } from '@puckeditor/core';\nimport type { ComponentData, Config } from '@puckeditor/core';\n\nimport { puckFetch } from '../../api/client.ts';\nimport {\n applyPropTransforms,\n type PuckPropTransforms,\n type PuckTemplatesConfig,\n} from '../../content-model.ts';\nimport { requireContentLocale } from '../../locale.ts';\nimport { generateId } from '../../utils.ts';\nimport { ICON_PROP, NAME_PROP } from '../outline-plugin/outline-tree.ts';\n\nexport type TemplateCategory = 'page' | 'section' | 'block';\n\nexport type TemplateAi = {\n description?: string;\n instructions?: string;\n};\n\nexport type TemplateEnvelope = {\n id: string;\n name: string | Record<string, string>;\n category: TemplateCategory;\n icon?: string;\n ai?: TemplateAi;\n group?: string;\n data: ComponentData[];\n};\n\nexport type BuiltinTemplate = TemplateEnvelope;\n\nexport type Template = TemplateEnvelope & {\n source: 'builtin' | 'custom';\n};\n\nexport type BrokenTemplate = {\n source: 'custom';\n broken: true;\n id: string;\n name: string;\n};\n\nexport type FetchedTemplates = {\n valid: Template[];\n broken: BrokenTemplate[];\n};\n\ntype RawFragment = { id: string; title: string } & Record<string, unknown>;\n\nconst asString = (value: unknown): string | undefined =>\n typeof value === 'string' && value ? value : undefined;\n\nconst parseCategory = (value: unknown): TemplateCategory | null =>\n value === 'page' || value === 'section' || value === 'block' ? value : null;\n\nexport const templateKey = (template: Template): string =>\n template.source === 'custom' ? template.id : `builtin-${template.id}`;\n\nexport const isRootLevelTemplate = (\n template: Template | BuiltinTemplate\n): boolean => template.category === 'section' || template.category === 'page';\n\nexport const templateLabel = (\n template: Template | BuiltinTemplate,\n locale: string\n): string => {\n const name = template.name;\n if (typeof name === 'string') return name;\n if (!name) return '';\n return (\n name[locale] ??\n name[locale.split('-')[0]] ??\n name.en ??\n Object.values(name)[0] ??\n ''\n );\n};\n\nexport const templateMatchesQuery = (\n template: Template,\n locale: string,\n query: string\n): boolean =>\n templateLabel(template, locale)\n .toLowerCase()\n .includes(query.trim().toLowerCase());\n\nexport const asBuiltinTemplates = (builtins: BuiltinTemplate[]): Template[] =>\n builtins.map((template) => ({ ...template, source: 'builtin' as const }));\n\nexport const mergeTemplates = (\n builtins: BuiltinTemplate[],\n custom: Template[]\n): Template[] => [...asBuiltinTemplates(builtins), ...custom];\n\nexport const isBrokenTemplate = (\n template: Template | BrokenTemplate\n): template is BrokenTemplate => 'broken' in template;\n\nconst mapFragment = (\n raw: RawFragment,\n config: PuckTemplatesConfig\n): Template | BrokenTemplate => {\n const broken = (): BrokenTemplate => ({\n source: 'custom',\n broken: true,\n id: raw.id,\n name: raw.title,\n });\n\n let data: ComponentData[];\n try {\n const parsed = JSON.parse(String(raw[config.dataField] ?? ''));\n data = Array.isArray(parsed) ? parsed : [parsed];\n } catch {\n console.warn(\n `puck-editor: template fragment \"${raw.id}\" has unparseable data`\n );\n return broken();\n }\n\n const category = parseCategory(raw[config.categoryField]);\n if (!category) {\n console.warn(\n `puck-editor: template fragment \"${raw.id}\" has an invalid category`\n );\n return broken();\n }\n\n const description = asString(raw[config.aiDescriptionField]);\n const instructions = asString(raw[config.aiInstructionsField]);\n const ai =\n description || instructions ? { description, instructions } : undefined;\n\n return {\n source: 'custom',\n id: raw.id,\n name: asString(raw.title) ?? raw.id,\n category,\n ...(ai ? { ai } : {}),\n data,\n };\n};\n\nexport const fetchTemplates = async (\n config: PuckTemplatesConfig,\n contentLocale: string\n): Promise<FetchedTemplates> => {\n const language = requireContentLocale(contentLocale);\n const { data } = await puckFetch<{ data: RawFragment[] }>(\n `/fragment/${config.fragmentType}?lang=${language}&limit=100`\n );\n const valid: Template[] = [];\n const broken: BrokenTemplate[] = [];\n for (const raw of data) {\n const mapped = mapFragment(raw, config);\n if (isBrokenTemplate(mapped)) broken.push(mapped);\n else valid.push(mapped);\n }\n return { valid, broken };\n};\n\nexport const expandTemplate = (\n template: Template,\n config: Config,\n outlineLabel?: string,\n propTransforms?: PuckPropTransforms\n): { content: ComponentData[]; skipped: number } => {\n const raw = applyPropTransforms(\n { root: { props: {} }, content: template.data, zones: {} },\n propTransforms,\n config,\n `template \"${template.id}\"`\n ).content as ComponentData[];\n\n let skipped = 0;\n const expanded = walkTree(\n { root: { props: {} }, content: raw, zones: {} },\n config,\n (content) =>\n content\n .filter((component) => {\n const known = Boolean(config.components[component.type]);\n if (!known) skipped++;\n return known;\n })\n .map((component) => ({\n ...component,\n props: {\n ...config.components[component.type]?.defaultProps,\n ...component.props,\n id: generateId(component.type),\n },\n }))\n );\n\n const content = expanded.content;\n if (\n outlineLabel &&\n template.category !== 'page' &&\n template.data.length === 1 &&\n content.length === 1\n ) {\n content[0] = {\n ...content[0],\n props: {\n ...content[0].props,\n [NAME_PROP]: outlineLabel,\n ...(template.icon ? { [ICON_PROP]: template.icon } : {}),\n },\n };\n }\n return { content, skipped };\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,kBAAkB;AAG3C,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SACEC,mBAAmB,QAGd,wBAAwB;AAC/B,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,SAAS,EAAEC,SAAS,QAAQ,mCAAmC;AAuCxE,MAAMC,QAAQ,GAAIC,KAAc,IAC9B,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,GAAGA,KAAK,GAAGC,SAAS;AAExD,MAAMC,aAAa,GAAIF,KAAc,IACnCA,KAAK,KAAK,MAAM,IAAIA,KAAK,KAAK,SAAS,IAAIA,KAAK,KAAK,OAAO,GAAGA,KAAK,GAAG,IAAI;AAE7E,OAAO,MAAMG,WAAW,GAAIC,QAAkB,IAC5CA,QAAQ,CAACC,MAAM,KAAK,QAAQ,GAAGD,QAAQ,CAACE,EAAE,GAAG,WAAWF,QAAQ,CAACE,EAAE,EAAE;AAEvE,OAAO,MAAMC,mBAAmB,GAC9BH,QAAoC,IACxBA,QAAQ,CAACI,QAAQ,KAAK,SAAS,IAAIJ,QAAQ,CAACI,QA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