| @@ -145,8 +145,40 @@ | ||
| 145 | 145 | } |
| 146 | 146 | return action; |
| 147 | 147 | }); |
| 148 | 148 | } |
| 149 | +function mergeAttributes(recordAttributes, moduleAttributes) { | |
| 150 | + if (!recordAttributes) { | |
| 151 | + return moduleAttributes; | |
| 152 | + } | |
| 153 | + if (!moduleAttributes) { | |
| 154 | + return recordAttributes; | |
| 155 | + } | |
| 156 | + const moduleById = new Map( | |
| 157 | + moduleAttributes.map( | |
| 158 | + (attribute) => [attribute.id, attribute] | |
| 159 | + ) | |
| 160 | + ); | |
| 161 | + const recordIds = new Set( | |
| 162 | + recordAttributes.map((attribute) => attribute.id) | |
| 163 | + ); | |
| 164 | + return [ | |
| 165 | + ...recordAttributes.map((attribute) => { | |
| 166 | + const moduleAttribute = moduleById.get(attribute.id); | |
| 167 | + if (!moduleAttribute?.isValid || !attribute.isValid) { | |
| 168 | + return { ...moduleAttribute, ...attribute }; | |
| 169 | + } | |
| 170 | + return { | |
| 171 | + ...moduleAttribute, | |
| 172 | + ...attribute, | |
| 173 | + isValid: { ...moduleAttribute.isValid, ...attribute.isValid } | |
| 174 | + }; | |
| 175 | + }), | |
| 176 | + ...moduleAttributes.filter( | |
| 177 | + (attribute) => !recordIds.has(attribute.id) | |
| 178 | + ) | |
| 179 | + ]; | |
| 180 | +} | |
| 149 | 181 | var DEFAULT_API_VERSION = 1; |
| 150 | 182 | function recordOverlay(record) { |
| 151 | 183 | return { |
| 152 | 184 | name: record.name, |
| @@ -181,8 +213,13 @@ | ||
| 181 | 213 | } |
| 182 | 214 | return { |
| 183 | 215 | apiVersion: DEFAULT_API_VERSION, |
| 184 | 216 | title: record.title ?? record.name, |
| 217 | + ...record.attributes ? { | |
| 218 | + attributes: resolveFields( | |
| 219 | + record.attributes | |
| 220 | + ) | |
| 221 | + } : {}, | |
| 185 | 222 | ...record.icon ? { icon: pendingIcon } : {}, |
| 186 | 223 | ...record.actions ? { |
| 187 | 224 | actions: withRenderableIcons( |
| 188 | 225 | record.actions, |
| @@ -203,16 +240,16 @@ | ||
| 203 | 240 | const metadata = module.default; |
| 204 | 241 | const moduleIcon = (0, import_element2.isValidElement)(metadata.icon) ? metadata.icon : void 0; |
| 205 | 242 | const icon = moduleIcon ?? (record.icon ? pendingIcon : void 0); |
| 206 | 243 | const actions = record.actions ?? metadata.actions; |
| 244 | + const attributes = mergeAttributes( | |
| 245 | + record.attributes, | |
| 246 | + metadata.attributes | |
| 247 | + ); | |
| 207 | 248 | return { |
| 208 | 249 | apiVersion: DEFAULT_API_VERSION, |
| 209 | 250 | ...metadata, |
| 210 | - ...metadata.attributes ? { | |
| 211 | - attributes: resolveFields( | |
| 212 | - metadata.attributes | |
| 213 | - ) | |
| 214 | - } : {}, | |
| 251 | + ...attributes ? { attributes: resolveFields(attributes) } : {}, | |
| 215 | 252 | icon, |
| 216 | 253 | /* |
| 217 | 254 | * `title` is required: |
| 218 | 255 | * - Server-side title wins |
| @@ -320,9 +357,26 @@ | ||
| 320 | 357 | } |
| 321 | 358 | function useWidgetHost() { |
| 322 | 359 | return (0, import_element3.useContext)(WidgetHostContext); |
| 323 | 360 | } |
| 361 | + | |
| 362 | +// packages/widget-primitives/build-module/widget-host/host-link.mjs | |
| 363 | +var import_element4 = __toESM(require_element(), 1); | |
| 364 | +var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1); | |
| 365 | +var HostLink = (0, import_element4.forwardRef)( | |
| 366 | + function HostLink2({ href, children, ...props }, ref) { | |
| 367 | + const { links } = useWidgetHost(); | |
| 368 | + const { download, target } = props; | |
| 369 | + const opensNewDocument = download !== void 0 && download !== false || /^_blank$/i.test(target ?? ""); | |
| 370 | + const path = links && !opensNewDocument ? links.match(href) : null; | |
| 371 | + if (links && path !== null) { | |
| 372 | + return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(links.Link, { ref, path, ...props, children }); | |
| 373 | + } | |
| 374 | + return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { ref, href, ...props, children }); | |
| 375 | + } | |
| 376 | +); | |
| 324 | 377 | export { |
| 378 | + HostLink, | |
| 325 | 379 | WidgetHostProvider, |
| 326 | 380 | WidgetRender, |
| 327 | 381 | registerFieldType, |
| 328 | 382 | registerIconResolver, |