@strapi/content-manager 0.0.0-experimental.cd782e586c4023aa5668811fa661cd4a851b69b3 → 0.0.0-experimental.ce5faa6c7fd5c9ab2a256f4595ef938ce908c95a

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 (54) hide show
  1. package/dist/admin/components/Widgets.js +4 -2
  2. package/dist/admin/components/Widgets.js.map +1 -1
  3. package/dist/admin/components/Widgets.mjs +4 -2
  4. package/dist/admin/components/Widgets.mjs.map +1 -1
  5. package/dist/admin/pages/EditView/components/InputRenderer.js +6 -3
  6. package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
  7. package/dist/admin/pages/EditView/components/InputRenderer.mjs +6 -3
  8. package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
  9. package/dist/admin/pages/EditView/utils/data.js +1 -1
  10. package/dist/admin/pages/EditView/utils/data.js.map +1 -1
  11. package/dist/admin/pages/EditView/utils/data.mjs +1 -1
  12. package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
  13. package/dist/admin/preview/components/InputPopover.js +108 -23
  14. package/dist/admin/preview/components/InputPopover.js.map +1 -1
  15. package/dist/admin/preview/components/InputPopover.mjs +91 -25
  16. package/dist/admin/preview/components/InputPopover.mjs.map +1 -1
  17. package/dist/admin/preview/hooks/usePreviewInputManager.js +3 -14
  18. package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -1
  19. package/dist/admin/preview/hooks/usePreviewInputManager.mjs +3 -14
  20. package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -1
  21. package/dist/admin/preview/pages/Preview.js +5 -31
  22. package/dist/admin/preview/pages/Preview.js.map +1 -1
  23. package/dist/admin/preview/pages/Preview.mjs +7 -33
  24. package/dist/admin/preview/pages/Preview.mjs.map +1 -1
  25. package/dist/admin/preview/utils/fieldUtils.js +88 -35
  26. package/dist/admin/preview/utils/fieldUtils.js.map +1 -1
  27. package/dist/admin/preview/utils/fieldUtils.mjs +87 -35
  28. package/dist/admin/preview/utils/fieldUtils.mjs.map +1 -1
  29. package/dist/admin/preview/utils/previewScript.js +74 -68
  30. package/dist/admin/preview/utils/previewScript.js.map +1 -1
  31. package/dist/admin/preview/utils/previewScript.mjs +74 -68
  32. package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
  33. package/dist/admin/src/preview/components/InputPopover.d.ts +1 -1
  34. package/dist/admin/src/preview/hooks/usePreviewInputManager.d.ts +2 -1
  35. package/dist/admin/src/preview/pages/Preview.d.ts +2 -0
  36. package/dist/admin/src/preview/utils/fieldUtils.d.ts +13 -5
  37. package/dist/admin/translations/en.json.js +1 -0
  38. package/dist/admin/translations/en.json.js.map +1 -1
  39. package/dist/admin/translations/en.json.mjs +1 -0
  40. package/dist/admin/translations/en.json.mjs.map +1 -1
  41. package/dist/admin/translations/es.json.js +1 -0
  42. package/dist/admin/translations/es.json.js.map +1 -1
  43. package/dist/admin/translations/es.json.mjs +1 -0
  44. package/dist/admin/translations/es.json.mjs.map +1 -1
  45. package/dist/admin/translations/fr.json.js +1 -0
  46. package/dist/admin/translations/fr.json.js.map +1 -1
  47. package/dist/admin/translations/fr.json.mjs +1 -0
  48. package/dist/admin/translations/fr.json.mjs.map +1 -1
  49. package/dist/server/homepage/services/homepage.js +1 -1
  50. package/dist/server/homepage/services/homepage.js.map +1 -1
  51. package/dist/server/homepage/services/homepage.mjs +1 -1
  52. package/dist/server/homepage/services/homepage.mjs.map +1 -1
  53. package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
  54. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,QAAQC,KAAU,KAAA,IAAA,IAAQA,UAAUG,SAAW,EAAA;wBACpFL,GAAG,CAACC,IAAI,GAAGC,KAAAA;wBACX,OAAOF,GAAAA;AACT;oBAEA,IAAIG,SAAAA,CAAUG,IAAI,KAAK,WAAa,EAAA;wBAClC,IAAIH,SAAAA,CAAUI,UAAU,EAAE;AACxB,4BAAA,MAAMC,iBACJnB,SAAUc,CAAAA,SAAAA,EAAWD,KAASZ,CAAAA,GAAAA,SAAAA,CAAUY,OAAOC,SAAaD,CAAAA,GAAAA,KAAAA;AAE9DF,4BAAAA,GAAG,CAACC,GAAI,CAAA,GAAGO,cAAeC,CAAAA,GAAG,CAAC,CAACC,aAAAA,GAC7BhB,QAASgB,CAAAA,aAAAA,EAAelB,UAAU,CAACW,SAAAA,CAAUQ,SAAS,CAAC,EAAEf,cAAc,EAAC,CAAA,CAAA;yBAErE,MAAA;AACL,4BAAA,MAAMY,i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AA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;;;;;;"}
1
+ {"version":3,"file":"data.js","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue === undefined ? initialValue : currentValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,QAAQC,KAAU,KAAA,IAAA,IAAQA,UAAUG,SAAW,EAAA;wBACpFL,GAAG,CAACC,IAAI,GAAGC,KAAAA;wBACX,OAAOF,GAAAA;AACT;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H,OAAOI,EAAE,KAAKrE,aAAaiE,MAAOI,CAAAA,EAAE,KAAK,IACrC,GAAA;oBAAE7D,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC,OAAO;oBAAEE,EAAIrE,EAAAA;iBACxC,GAAA;oBAAEQ,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC;AAAQ,iBAAA;gBAEzC,OAAOC,aAAAA;AACT,aAAA,CAAA;AAEA,YAAA;AACF;;AAGA,QAAA,IAAIN,iBAAiB9D,SAAW,EAAA;YAC9B+C,MAAM,CAACC,SAAS,GAAGc,YAAAA;SACd,MAAA,IAAI1B,iBAAiBpC,SAAW,EAAA;YACrC+C,MAAM,CAACC,SAAS,GAAGZ,YAAAA;SACd,MAAA;YACL,IAAIY,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;;;;;;"}
@@ -174,7 +174,7 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
174
174
  // 🔹 Handle components
175
175
  if (attrDef.type === 'component') {
176
176
  const compSchema = components[attrDef.component];
177
- const value = currentValue ?? initialValue;
177
+ const value = currentValue === undefined ? initialValue : currentValue;
178
178
  if (!value) {
179
179
  result[attrName] = attrDef.repeatable ? [] : null;
180
180
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"data.mjs","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,QAAQC,KAAU,KAAA,IAAA,IAAQA,UAAUG,SAAW,EAAA;wBACpFL,GAAG,CAACC,IAAI,GAAGC,KAAAA;wBACX,OAAOF,GAAAA;AACT;oBAEA,IAAIG,SAAAA,CAAUG,IAAI,KAAK,WAAa,EAAA;wBAClC,IAAIH,SAAAA,CAAUI,UAAU,EAAE;AACxB,4BAAA,MAAMC,iBACJnB,SAAUc,CAAAA,SAAAA,EAAWD,KAASZ,CAAAA,GAAAA,SAAAA,CAAUY,OAAOC,SAAaD,CAAAA,GAAAA,KAAAA;AAE9DF,4BAAAA,GAAG,CAACC,GAAI,CAAA,GAAGO,cAAeC,CAAAA,GAAG,CAAC,CAACC,aAAAA,GAC7BhB,QAASgB,CAAAA,aAAAA,EAAelB,UAAU,CAACW,SAAAA,CAAUQ,SAAS,CAAC,EAAEf,cAAc,EAAC,CAAA,CAAA;yBAErE,MAAA;AACL,4BAAA,MAAMY,iBACJnB,SAAUc,CAAAA,SAAAA,EAAWD,KAASZ,CAAA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;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"data.mjs","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue === undefined ? initialValue : currentValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,QAAQC,KAAU,KAAA,IAAA,IAAQA,UAAUG,SAAW,EAAA;wBACpFL,GAAG,CAACC,IAAI,GAAGC,KAAAA;wBACX,OAAOF,GAAAA;AACT;oBAEA,IAAIG,SAAAA,CAAUG,IAAI,KAAK,WAAa,EAAA;w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AAK,IACrC,GAAA;oBAAE7D,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC,OAAO;oBAAEE,EAAIrE,EAAAA;iBACxC,GAAA;oBAAEQ,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC;AAAQ,iBAAA;gBAEzC,OAAOC,aAAAA;AACT,aAAA,CAAA;AAEA,YAAA;AACF;;AAGA,QAAA,IAAIN,iBAAiB9D,SAAW,EAAA;YAC9B+C,MAAM,CAACC,SAAS,GAAGc,YAAAA;SACd,MAAA,IAAI1B,iBAAiBpC,SAAW,EAAA;YACrC+C,MAAM,CAACC,SAAS,GAAGZ,YAAAA;SACd,MAAA;YACL,IAAIY,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;"}
@@ -1,31 +1,121 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- require('react');
4
+ var React = require('react');
5
5
  var strapiAdmin = require('@strapi/admin/strapi-admin');
6
6
  var designSystem = require('@strapi/design-system');
7
7
  var InputRenderer = require('../../pages/EditView/components/InputRenderer.js');
8
8
  var Preview = require('../pages/Preview.js');
9
+ var constants = require('../utils/constants.js');
9
10
  var fieldUtils = require('../utils/fieldUtils.js');
10
11
 
12
+ function _interopNamespaceDefault(e) {
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
30
+
11
31
  const [InputPopoverProvider, useInputPopoverContext] = strapiAdmin.createContext('InputPopover');
12
- const InputPopover = ({ documentResponse })=>{
13
- const iframeRef = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.iframeRef);
14
- const popoverField = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.popoverField);
15
- const setPopoverField = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.setPopoverField);
16
- if (!popoverField || !documentResponse.schema || !iframeRef.current) {
32
+ function useHasInputPopoverParent() {
33
+ const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
34
+ // useContext will return undefined if the called is not wrapped in the provider
35
+ return context !== undefined;
36
+ }
37
+ /* -------------------------------------------------------------------------------------------------
38
+ * InputPopover
39
+ * -----------------------------------------------------------------------------------------------*/ const InputPopover = ({ documentResponse })=>{
40
+ const iframeRef = Preview.usePreviewContext('InputPopover', (state)=>state.iframeRef);
41
+ const popoverField = Preview.usePreviewContext('InputPopover', (state)=>state.popoverField);
42
+ const setPopoverField = Preview.usePreviewContext('InputPopover', (state)=>state.setPopoverField);
43
+ const document = Preview.usePreviewContext('InputPopover', (state)=>state.document);
44
+ const schema = Preview.usePreviewContext('InputPopover', (state)=>state.schema);
45
+ const components = Preview.usePreviewContext('InputPopover', (state)=>state.components);
46
+ const { toggleNotification } = strapiAdmin.useNotification();
47
+ React__namespace.useEffect(()=>{
48
+ /**
49
+ * We receive window events sent from the user's preview via the injected script.
50
+ * We listen to the ones here that target a specific field.
51
+ */ const handleMessage = (event)=>{
52
+ // Only listen to events from the preview iframe
53
+ if (iframeRef.current) {
54
+ const previewOrigin = new URL(iframeRef.current?.src).origin;
55
+ if (event.origin !== previewOrigin) {
56
+ return;
57
+ }
58
+ }
59
+ if (event.data?.type === constants.INTERNAL_EVENTS.STRAPI_FIELD_FOCUS_INTENT) {
60
+ const fieldMetaData = fieldUtils.parseFieldMetaData(event.data.payload.path);
61
+ // TODO: check if notification better
62
+ if (!fieldMetaData) {
63
+ toggleNotification({
64
+ type: 'warning',
65
+ message: 'Incomplete strapiSource attribute'
66
+ });
67
+ return;
68
+ }
69
+ /**
70
+ * Ignore (for now) content that comes from separate API requests than the one for the
71
+ * current document. This doesn't do anything about fields that may come from relations to
72
+ * the current document however.
73
+ */ if (fieldMetaData.documentId !== document.documentId) {
74
+ toggleNotification({
75
+ type: 'warning',
76
+ message: 'This field comes from a different document'
77
+ });
78
+ return;
79
+ }
80
+ try {
81
+ const attribute = fieldUtils.getAttributeSchemaFromPath({
82
+ path: fieldMetaData.path,
83
+ components,
84
+ schema,
85
+ document
86
+ });
87
+ // We're able to handle the field, set it in context so the popover can pick it up
88
+ setPopoverField({
89
+ ...fieldMetaData,
90
+ position: event.data.payload.position,
91
+ attribute
92
+ });
93
+ } catch (error) {
94
+ if (error instanceof Error) {
95
+ toggleNotification({
96
+ type: 'warning',
97
+ message: error.message
98
+ });
99
+ }
100
+ }
101
+ }
102
+ };
103
+ window.addEventListener('message', handleMessage);
104
+ return ()=>{
105
+ window.removeEventListener('message', handleMessage);
106
+ };
107
+ }, [
108
+ components,
109
+ document,
110
+ iframeRef,
111
+ schema,
112
+ setPopoverField,
113
+ toggleNotification
114
+ ]);
115
+ if (!popoverField || !iframeRef.current) {
17
116
  return null;
18
117
  }
19
118
  const iframeRect = iframeRef.current.getBoundingClientRect();
20
- const pathParts = fieldUtils.parsePathWithIndices(popoverField.path);
21
- const attributeSchema = fieldUtils.getAttributeSchema({
22
- pathParts,
23
- schema: documentResponse.schema,
24
- components: documentResponse.components
25
- });
26
- if (!attributeSchema) {
27
- return null;
28
- }
29
119
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
30
120
  children: [
31
121
  /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
@@ -58,11 +148,11 @@ const InputPopover = ({ documentResponse })=>{
58
148
  width: "400px",
59
149
  children: /*#__PURE__*/ jsxRuntime.jsx(InputRenderer.InputRenderer, {
60
150
  document: documentResponse,
61
- attribute: attributeSchema,
151
+ attribute: popoverField.attribute,
62
152
  // TODO: retrieve the proper label from the layout
63
153
  label: popoverField.path,
64
- name: popoverField.path.replace('[', '.').replace(']', ''),
65
- type: attributeSchema.type,
154
+ name: popoverField.path,
155
+ type: popoverField.attribute.type,
66
156
  visible: true
67
157
  })
68
158
  })
@@ -73,11 +163,6 @@ const InputPopover = ({ documentResponse })=>{
73
163
  ]
74
164
  });
75
165
  };
76
- function useHasInputPopoverParent() {
77
- const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
78
- // useContext will return undefined if the called is not wrapped in the provider
79
- return context !== undefined;
80
- }
81
166
 
82
167
  exports.InputPopover = InputPopover;
83
168
  exports.useHasInputPopoverParent = useHasInputPopoverParent;
@@ -1 +1 @@
1
- {"version":3,"file":"InputPopover.js","sources":["../../../../admin/src/preview/components/InputPopover.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext } from '@strapi/admin/strapi-admin';\nimport { Box, Popover } from '@strapi/design-system';\n\nimport { type UseDocument } from '../../hooks/useDocument';\nimport { InputRenderer } from '../../pages/EditView/components/InputRenderer';\nimport { usePreviewContext } from '../pages/Preview';\nimport { parsePathWithIndices, getAttributeSchema } from '../utils/fieldUtils';\n\n/**\n * No need for actual data in the context. It's just to let children check if they're rendered\n * inside of a preview InputPopover without relying on prop drilling.\n */\ninterface InputPopoverContextValue {}\n\nconst [InputPopoverProvider, useInputPopoverContext] =\n createContext<InputPopoverContextValue>('InputPopover');\n\nconst InputPopover = ({ documentResponse }: { documentResponse: ReturnType<UseDocument> }) => {\n const iframeRef = usePreviewContext('VisualEditingPopover', (state) => state.iframeRef);\n const popoverField = usePreviewContext('VisualEditingPopover', (state) => state.popoverField);\n const setPopoverField = usePreviewContext(\n 'VisualEditingPopover',\n (state) => state.setPopoverField\n );\n\n if (!popoverField || !documentResponse.schema || !iframeRef.current) {\n return null;\n }\n\n const iframeRect = iframeRef.current.getBoundingClientRect();\n\n const pathParts = parsePathWithIndices(popoverField.path);\n const attributeSchema = getAttributeSchema({\n pathParts,\n schema: documentResponse.schema,\n components: documentResponse.components,\n });\n\n if (!attributeSchema) {\n return null;\n }\n\n return (\n <>\n {/**\n * Overlay an empty div on top of the iframe while the popover is open so it can\n * intercept clicks. Without it, we wouldn't be able to close the popover by clicking outside,\n * because the click would be detected by the iframe window, not by the admin.\n **/}\n <Box\n position={'fixed'}\n top={iframeRect.top + 'px'}\n left={iframeRect.left + 'px'}\n width={iframeRect.width + 'px'}\n height={iframeRect.height + 'px'}\n zIndex={4}\n />\n <InputPopoverProvider>\n <Popover.Root open={true} onOpenChange={(open) => !open && setPopoverField(null)}>\n <Popover.Trigger>\n <Box\n position=\"fixed\"\n width={popoverField.position.width + 'px'}\n height={popoverField.position.height + 'px'}\n top={0}\n left={0}\n transform={`translate(${iframeRect.left + popoverField.position.left}px, ${iframeRect.top + popoverField.position.top}px)`}\n />\n </Popover.Trigger>\n <Popover.Content sideOffset={4}>\n <Box padding={4} width=\"400px\">\n {/* @ts-expect-error the \"type\" property clashes for some reason */}\n <InputRenderer\n document={documentResponse}\n attribute={attributeSchema}\n // TODO: retrieve the proper label from the layout\n label={popoverField.path}\n name={popoverField.path.replace('[', '.').replace(']', '')}\n type={attributeSchema.type}\n visible={true}\n />\n </Box>\n </Popover.Content>\n </Popover.Root>\n </InputPopoverProvider>\n </>\n );\n};\n\nfunction useHasInputPopoverParent() {\n const context = useInputPopoverContext('useHasInputPopoverParent', () => true, false);\n\n // useContext will return undefined if the called is not wrapped in the provider\n return context !== undefined;\n}\n\nexport { InputPopover, useHasInputPopoverParent };\n"],"names":["InputPopoverProvider","useInputPopoverContext","createContext","InputPopover","documentResponse","iframeRef","usePreviewContext","state","popoverField","setPopoverField","schema","current","iframeRect","getBoundingClientRect","pathParts","parsePathWithIndices","path","attributeSchema","getAttributeSchema","components","_jsxs","_Fragment","_jsx","Box","position","top","left","width","height","zIndex","Popover","Root","open","onOpenChange","Trigger","transform","Content","sideOffset","padding","InputRenderer","document","attribute","label","name","replace","type","visible","useHasInputPopoverParent","context","undefined"],"mappings":";;;;;;;;;;AAgBA,MAAM,CAACA,oBAAAA,EAAsBC,sBAAuB,CAAA,GAClDC,yBAAwC,CAAA,cAAA,CAAA;AAE1C,MAAMC,YAAe,GAAA,CAAC,EAAEC,gBAAgB,EAAiD,GAAA;AACvF,IAAA,MAAMC,YAAYC,yBAAkB,CAAA,sBAAA,EAAwB,CAACC,KAAAA,GAAUA,MAAMF,SAAS,CAAA;AACtF,IAAA,MAAMG,eAAeF,yBAAkB,CAAA,sBAAA,EAAwB,CAACC,KAAAA,GAAUA,MAAMC,YAAY,CAAA;AAC5F,IAAA,MAAMC,kBAAkBH,yBACtB,CAAA,sBAAA,EACA,CAACC,KAAAA,GAAUA,MAAME,eAAe,CAAA;IAGlC,IAAI,CAACD,gBAAgB,CAACJ,gBAAAA,CAAiBM,MAAM,IAAI,CAACL,SAAUM,CAAAA,OAAO,EAAE;QACnE,OAAO,IAAA;AACT;AAEA,IAAA,MAAMC,UAAaP,GAAAA,SAAAA,CAAUM,OAAO,CAACE,qBAAqB,EAAA;IAE1D,MAAMC,SAAAA,GAAYC,+BAAqBP,CAAAA,YAAAA,CAAaQ,IAAI,CAAA;AACxD,IAAA,MAAMC,kBAAkBC,6BAAmB,CAAA;AACzCJ,QAAAA,SAAAA;AACAJ,QAAAA,MAAAA,EAAQN,iBAAiBM,MAAM;AAC/BS,QAAAA,UAAAA,EAAYf,iBAAiBe;AAC/B,KAAA,CAAA;AAEA,IAAA,IAAI,CAACF,eAAiB,EAAA;QACpB,OAAO,IAAA;AACT;IAEA,qBACEG,eAAA,CAAAC,mBAAA,EAAA;;0BAMEC,cAACC,CAAAA,gBAAAA,EAAAA;gBACCC,QAAU,EAAA,OAAA;gBACVC,GAAKb,EAAAA,UAAAA,CAAWa,GAAG,GAAG,IAAA;gBACtBC,IAAMd,EAAAA,UAAAA,CAAWc,IAAI,GAAG,IAAA;gBACxBC,KAAOf,EAAAA,UAAAA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AaQ,IAAI,CAAC4B,OAAO,CAAC,GAAK,EAAA,GAAA,CAAA,CAAKA,OAAO,CAAC,GAAK,EAAA,EAAA,CAAA;AACvDC,oCAAAA,IAAAA,EAAM5B,gBAAgB4B,IAAI;oCAC1BC,OAAS,EAAA;;;;;;;;;AAQzB;AAEA,SAASC,wBAAAA,GAAAA;AACP,IAAA,MAAMC,OAAU/C,GAAAA,sBAAAA,CAAuB,0BAA4B,EAAA,IAAM,IAAM,EAAA,KAAA,CAAA;;AAG/E,IAAA,OAAO+C,OAAYC,KAAAA,SAAAA;AACrB;;;;;"}
1
+ {"version":3,"file":"InputPopover.js","sources":["../../../../admin/src/preview/components/InputPopover.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, useNotification } from '@strapi/admin/strapi-admin';\nimport { Box, Popover } from '@strapi/design-system';\n\nimport { type UseDocument } from '../../hooks/useDocument';\nimport { InputRenderer } from '../../pages/EditView/components/InputRenderer';\nimport { usePreviewContext } from '../pages/Preview';\nimport { INTERNAL_EVENTS } from '../utils/constants';\nimport { parseFieldMetaData, getAttributeSchemaFromPath } from '../utils/fieldUtils';\n\n/* -------------------------------------------------------------------------------------------------\n * Context utils\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * No need for actual data in the context. It's just to let children check if they're rendered\n * inside of a preview InputPopover without relying on prop drilling.\n */\ninterface InputPopoverContextValue {}\n\nconst [InputPopoverProvider, useInputPopoverContext] =\n createContext<InputPopoverContextValue>('InputPopover');\n\nfunction useHasInputPopoverParent() {\n const context = useInputPopoverContext('useHasInputPopoverParent', () => true, false);\n\n // useContext will return undefined if the called is not wrapped in the provider\n return context !== undefined;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * InputPopover\n * -----------------------------------------------------------------------------------------------*/\n\nconst InputPopover = ({ documentResponse }: { documentResponse: ReturnType<UseDocument> }) => {\n const iframeRef = usePreviewContext('InputPopover', (state) => state.iframeRef);\n const popoverField = usePreviewContext('InputPopover', (state) => state.popoverField);\n const setPopoverField = usePreviewContext('InputPopover', (state) => state.setPopoverField);\n const document = usePreviewContext('InputPopover', (state) => state.document);\n const schema = usePreviewContext('InputPopover', (state) => state.schema);\n const components = usePreviewContext('InputPopover', (state) => state.components);\n const { toggleNotification } = useNotification();\n\n React.useEffect(() => {\n /**\n * We receive window events sent from the user's preview via the injected script.\n * We listen to the ones here that target a specific field.\n */\n const handleMessage = (event: MessageEvent) => {\n // Only listen to events from the preview iframe\n if (iframeRef.current) {\n const previewOrigin = new URL(iframeRef.current?.src).origin;\n if (event.origin !== previewOrigin) {\n return;\n }\n }\n\n if (event.data?.type === INTERNAL_EVENTS.STRAPI_FIELD_FOCUS_INTENT) {\n const fieldMetaData = parseFieldMetaData(event.data.payload.path);\n\n // TODO: check if notification better\n if (!fieldMetaData) {\n toggleNotification({\n type: 'warning',\n message: 'Incomplete strapiSource attribute',\n });\n return;\n }\n\n /**\n * Ignore (for now) content that comes from separate API requests than the one for the\n * current document. This doesn't do anything about fields that may come from relations to\n * the current document however.\n */\n if (fieldMetaData.documentId !== document.documentId) {\n toggleNotification({\n type: 'warning',\n message: 'This field comes from a different document',\n });\n return;\n }\n\n try {\n const attribute = getAttributeSchemaFromPath({\n path: fieldMetaData.path,\n components,\n schema,\n document,\n });\n\n // We're able to handle the field, set it in context so the popover can pick it up\n setPopoverField({ ...fieldMetaData, position: event.data.payload.position, attribute });\n } catch (error) {\n if (error instanceof Error) {\n toggleNotification({ type: 'warning', message: error.message });\n }\n }\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => {\n window.removeEventListener('message', handleMessage);\n };\n }, [components, document, iframeRef, schema, setPopoverField, toggleNotification]);\n if (!popoverField || !iframeRef.current) {\n return null;\n }\n\n const iframeRect = iframeRef.current.getBoundingClientRect();\n\n return (\n <>\n {/**\n * Overlay an empty div on top of the iframe while the popover is open so it can\n * intercept clicks. Without it, we wouldn't be able to close the popover by clicking outside,\n * because the click would be detected by the iframe window, not by the admin.\n **/}\n <Box\n position={'fixed'}\n top={iframeRect.top + 'px'}\n left={iframeRect.left + 'px'}\n width={iframeRect.width + 'px'}\n height={iframeRect.height + 'px'}\n zIndex={4}\n />\n <InputPopoverProvider>\n <Popover.Root open={true} onOpenChange={(open) => !open && setPopoverField(null)}>\n <Popover.Trigger>\n <Box\n position=\"fixed\"\n width={popoverField.position.width + 'px'}\n height={popoverField.position.height + 'px'}\n top={0}\n left={0}\n transform={`translate(${iframeRect.left + popoverField.position.left}px, ${iframeRect.top + popoverField.position.top}px)`}\n />\n </Popover.Trigger>\n <Popover.Content sideOffset={4}>\n <Box padding={4} width=\"400px\">\n {/* @ts-expect-error the types of `attribute` clash for some reason */}\n <InputRenderer\n document={documentResponse}\n attribute={popoverField.attribute}\n // TODO: retrieve the proper label from the layout\n label={popoverField.path}\n name={popoverField.path}\n type={popoverField.attribute.type}\n visible={true}\n />\n </Box>\n </Popover.Content>\n </Popover.Root>\n </InputPopoverProvider>\n </>\n );\n};\n\nexport { InputPopover, useHasInputPopoverParent };\n"],"names":["InputPopoverProvider","useInputPopoverContext","createContext","useHasInputPopoverParent","context","undefined","InputPopover","documentResponse","iframeRef","usePreviewContext","state","popoverField","setPopoverField","document","schema","components","toggleNotification","useNotification","React","useEffect","handleMessage","event","current","previewOrigin","URL","src","origin","data","type","INTERNAL_EVENTS","STRAPI_FIELD_FOCUS_INTENT","fieldMetaData","parseFieldMetaData","payload","path","message","documentId","attribute","getAttributeSchemaFromPath","position","error","Error","window","addEventListener","removeEventListener","iframeRect","getBoundingClientRect","_jsxs","_Fragment","_jsx","Box","top","left","width","height","zIndex","Popover","Root","open","onOpenChange","Trigger","transform","Content","sideOffset","padding","InputRenderer","label","name","visible"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,CAACA,oBAAAA,EAAsBC,sBAAuB,CAAA,GAClDC,yBAAwC,CAAA,cAAA,CAAA;AAE1C,SAASC,wBAAAA,GAAAA;AACP,IAAA,MAAMC,OAAUH,GAAAA,sBAAAA,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G,GAAGxC,YAAAA,CAAa4B,QAAQ,CAACY,GAAG,CAAC,GAAG;;;AAG7H,sCAAAF,cAAA,CAACO,qBAAQM,OAAO,EAAA;4BAACC,UAAY,EAAA,CAAA;AAC3B,4BAAA,QAAA,gBAAAd,cAACC,CAAAA,gBAAAA,EAAAA;gCAAIc,OAAS,EAAA,CAAA;gCAAGX,KAAM,EAAA,OAAA;AAErB,gCAAA,QAAA,gBAAAJ,cAACgB,CAAAA,2BAAAA,EAAAA;oCACCpD,QAAUN,EAAAA,gBAAAA;AACV8B,oCAAAA,SAAAA,EAAW1B,aAAa0B,SAAS;;AAEjC6B,oCAAAA,KAAAA,EAAOvD,aAAauB,IAAI;AACxBiC,oCAAAA,IAAAA,EAAMxD,aAAauB,IAAI;oCACvBN,IAAMjB,EAAAA,YAAAA,CAAa0B,SAAS,CAACT,IAAI;oCACjCwC,OAAS,EAAA;;;;;;;;;AAQzB;;;;;"}
@@ -1,29 +1,100 @@
1
1
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
- import 'react';
3
- import { createContext } from '@strapi/admin/strapi-admin';
2
+ import * as React from 'react';
3
+ import { createContext, useNotification } from '@strapi/admin/strapi-admin';
4
4
  import { Box, Popover } from '@strapi/design-system';
5
5
  import { InputRenderer as MemoizedInputRenderer } from '../../pages/EditView/components/InputRenderer.mjs';
6
6
  import { usePreviewContext } from '../pages/Preview.mjs';
7
- import { parsePathWithIndices, getAttributeSchema } from '../utils/fieldUtils.mjs';
7
+ import { INTERNAL_EVENTS } from '../utils/constants.mjs';
8
+ import { parseFieldMetaData, getAttributeSchemaFromPath } from '../utils/fieldUtils.mjs';
8
9
 
9
10
  const [InputPopoverProvider, useInputPopoverContext] = createContext('InputPopover');
10
- const InputPopover = ({ documentResponse })=>{
11
- const iframeRef = usePreviewContext('VisualEditingPopover', (state)=>state.iframeRef);
12
- const popoverField = usePreviewContext('VisualEditingPopover', (state)=>state.popoverField);
13
- const setPopoverField = usePreviewContext('VisualEditingPopover', (state)=>state.setPopoverField);
14
- if (!popoverField || !documentResponse.schema || !iframeRef.current) {
11
+ function useHasInputPopoverParent() {
12
+ const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
13
+ // useContext will return undefined if the called is not wrapped in the provider
14
+ return context !== undefined;
15
+ }
16
+ /* -------------------------------------------------------------------------------------------------
17
+ * InputPopover
18
+ * -----------------------------------------------------------------------------------------------*/ const InputPopover = ({ documentResponse })=>{
19
+ const iframeRef = usePreviewContext('InputPopover', (state)=>state.iframeRef);
20
+ const popoverField = usePreviewContext('InputPopover', (state)=>state.popoverField);
21
+ const setPopoverField = usePreviewContext('InputPopover', (state)=>state.setPopoverField);
22
+ const document = usePreviewContext('InputPopover', (state)=>state.document);
23
+ const schema = usePreviewContext('InputPopover', (state)=>state.schema);
24
+ const components = usePreviewContext('InputPopover', (state)=>state.components);
25
+ const { toggleNotification } = useNotification();
26
+ React.useEffect(()=>{
27
+ /**
28
+ * We receive window events sent from the user's preview via the injected script.
29
+ * We listen to the ones here that target a specific field.
30
+ */ const handleMessage = (event)=>{
31
+ // Only listen to events from the preview iframe
32
+ if (iframeRef.current) {
33
+ const previewOrigin = new URL(iframeRef.current?.src).origin;
34
+ if (event.origin !== previewOrigin) {
35
+ return;
36
+ }
37
+ }
38
+ if (event.data?.type === INTERNAL_EVENTS.STRAPI_FIELD_FOCUS_INTENT) {
39
+ const fieldMetaData = parseFieldMetaData(event.data.payload.path);
40
+ // TODO: check if notification better
41
+ if (!fieldMetaData) {
42
+ toggleNotification({
43
+ type: 'warning',
44
+ message: 'Incomplete strapiSource attribute'
45
+ });
46
+ return;
47
+ }
48
+ /**
49
+ * Ignore (for now) content that comes from separate API requests than the one for the
50
+ * current document. This doesn't do anything about fields that may come from relations to
51
+ * the current document however.
52
+ */ if (fieldMetaData.documentId !== document.documentId) {
53
+ toggleNotification({
54
+ type: 'warning',
55
+ message: 'This field comes from a different document'
56
+ });
57
+ return;
58
+ }
59
+ try {
60
+ const attribute = getAttributeSchemaFromPath({
61
+ path: fieldMetaData.path,
62
+ components,
63
+ schema,
64
+ document
65
+ });
66
+ // We're able to handle the field, set it in context so the popover can pick it up
67
+ setPopoverField({
68
+ ...fieldMetaData,
69
+ position: event.data.payload.position,
70
+ attribute
71
+ });
72
+ } catch (error) {
73
+ if (error instanceof Error) {
74
+ toggleNotification({
75
+ type: 'warning',
76
+ message: error.message
77
+ });
78
+ }
79
+ }
80
+ }
81
+ };
82
+ window.addEventListener('message', handleMessage);
83
+ return ()=>{
84
+ window.removeEventListener('message', handleMessage);
85
+ };
86
+ }, [
87
+ components,
88
+ document,
89
+ iframeRef,
90
+ schema,
91
+ setPopoverField,
92
+ toggleNotification
93
+ ]);
94
+ if (!popoverField || !iframeRef.current) {
15
95
  return null;
16
96
  }
17
97
  const iframeRect = iframeRef.current.getBoundingClientRect();
18
- const pathParts = parsePathWithIndices(popoverField.path);
19
- const attributeSchema = getAttributeSchema({
20
- pathParts,
21
- schema: documentResponse.schema,
22
- components: documentResponse.components
23
- });
24
- if (!attributeSchema) {
25
- return null;
26
- }
27
98
  return /*#__PURE__*/ jsxs(Fragment, {
28
99
  children: [
29
100
  /*#__PURE__*/ jsx(Box, {
@@ -56,11 +127,11 @@ const InputPopover = ({ documentResponse })=>{
56
127
  width: "400px",
57
128
  children: /*#__PURE__*/ jsx(MemoizedInputRenderer, {
58
129
  document: documentResponse,
59
- attribute: attributeSchema,
130
+ attribute: popoverField.attribute,
60
131
  // TODO: retrieve the proper label from the layout
61
132
  label: popoverField.path,
62
- name: popoverField.path.replace('[', '.').replace(']', ''),
63
- type: attributeSchema.type,
133
+ name: popoverField.path,
134
+ type: popoverField.attribute.type,
64
135
  visible: true
65
136
  })
66
137
  })
@@ -71,11 +142,6 @@ const InputPopover = ({ documentResponse })=>{
71
142
  ]
72
143
  });
73
144
  };
74
- function useHasInputPopoverParent() {
75
- const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
76
- // useContext will return undefined if the called is not wrapped in the provider
77
- return context !== undefined;
78
- }
79
145
 
80
146
  export { InputPopover, useHasInputPopoverParent };
81
147
  //# sourceMappingURL=InputPopover.mjs.map