@atlaskit/native-embeds-common 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1 +1,15 @@
1
1
  # @atlaskit/native-embeds-common
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`71180287b9fed`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/71180287b9fed) -
14
+ pen inline prompt when ask rovo is clicked on a maui app and send the context to the api
15
+ - Updated dependencies
package/dist/cjs/index.js CHANGED
@@ -21,16 +21,46 @@ Object.defineProperty(exports, "DEFAULT_ALIGNMENT", {
21
21
  return _constants.DEFAULT_ALIGNMENT;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "EDITOR_TOOLBAR_HANDLER_KEYS", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _constants.EDITOR_TOOLBAR_HANDLER_KEYS;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "NATIVE_EMBED_PARAMETER_DEFAULTS", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _constants.NATIVE_EMBED_PARAMETER_DEFAULTS;
34
+ }
35
+ });
24
36
  Object.defineProperty(exports, "createEditorToolbarActions", {
25
37
  enumerable: true,
26
38
  get: function get() {
27
39
  return _utils.createEditorToolbarActions;
28
40
  }
29
41
  });
30
- Object.defineProperty(exports, "updateParameters", {
42
+ Object.defineProperty(exports, "getParameter", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _utils.getParameter;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "getParameters", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _utils.getParameters;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "setParameter", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _utils.setParameter;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "setParameters", {
31
61
  enumerable: true,
32
62
  get: function get() {
33
- return _utils.updateParameters;
63
+ return _utils.setParameters;
34
64
  }
35
65
  });
36
66
  var _constants = require("./utils/constants");
@@ -3,27 +3,39 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DEFAULT_ALIGNMENT = exports.BUILTIN_TOOLBAR_KEYS = exports.ALIGNMENT_VALUES = void 0;
6
+ exports.NATIVE_EMBED_PARAMETER_DEFAULTS = exports.EDITOR_TOOLBAR_HANDLER_KEYS = exports.DEFAULT_ALIGNMENT = exports.BUILTIN_TOOLBAR_KEYS = exports.ALIGNMENT_VALUES = void 0;
7
7
  // Alignment constants
8
8
  var ALIGNMENT_VALUES = exports.ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
9
9
  var DEFAULT_ALIGNMENT = exports.DEFAULT_ALIGNMENT = 'center';
10
+ var NATIVE_EMBED_PARAMETER_DEFAULTS = exports.NATIVE_EMBED_PARAMETER_DEFAULTS = {
11
+ url: undefined,
12
+ alwaysShowTitle: false,
13
+ alignment: DEFAULT_ALIGNMENT,
14
+ displayText: undefined,
15
+ height: 600,
16
+ width: undefined
17
+ };
10
18
 
11
19
  /**
12
20
  * Built-in keys that can be referenced in the `items` and `moreItems` arrays.
13
21
  *
14
- * Toolbar keys: REFRESH, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
22
+ * Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
15
23
  * More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
16
24
  * Shared: SEPARATOR (usable in both)
17
25
  */
18
26
  var BUILTIN_TOOLBAR_KEYS = exports.BUILTIN_TOOLBAR_KEYS = {
27
+ ASK_ROVO: 'askRovo',
19
28
  REFRESH: 'refresh',
29
+ EDIT: 'edit',
20
30
  EMBED: 'embed',
21
31
  BORDER: 'border',
22
32
  ALIGNMENT: 'alignment',
23
33
  OPEN_IN_NEW_WINDOW: 'openInNewWindow',
34
+ EDIT_URL: 'editUrl',
24
35
  ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
25
36
  SET_EMBED_TYPE: 'setEmbedType',
26
37
  COPY_LINK: 'copyLink',
27
38
  DELETE: 'delete',
28
39
  SEPARATOR: 'separator'
29
- };
40
+ };
41
+ var EDITOR_TOOLBAR_HANDLER_KEYS = exports.EDITOR_TOOLBAR_HANDLER_KEYS = ['onAlignmentClick', 'onAppearanceClick', 'onAskRovoClick', 'onCopyLinkClick', 'onChangeBorderClick', 'onDeleteClick', 'onEditUrlClick', 'onEditClick', 'onOpenInNewWindowClick', 'onRefreshClick', 'onSetEmbedTypeClick', 'onShowTitleClick'];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -4,25 +4,138 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createEditorToolbarActions = void 0;
8
- exports.updateParameters = updateParameters;
7
+ exports.getParameter = exports.createEditorToolbarActions = void 0;
8
+ exports.getParameters = getParameters;
9
+ exports.setParameters = exports.setParameter = void 0;
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
+ var _constants = require("./constants");
11
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ var getMacroParamsRecord = function getMacroParamsRecord(parameters) {
17
+ if (!(parameters !== null && parameters !== void 0 && parameters.macroParams) || (0, _typeof2.default)(parameters.macroParams) !== 'object') {
18
+ return {};
19
+ }
20
+ return parameters.macroParams;
21
+ };
22
+ var unwrapMacroParamValue = function unwrapMacroParamValue(macroParamValue) {
23
+ if (macroParamValue && (0, _typeof2.default)(macroParamValue) === 'object' && 'value' in macroParamValue) {
24
+ return macroParamValue.value;
25
+ }
26
+ return macroParamValue;
27
+ };
28
+ var PARAMETER_VALIDATORS = {
29
+ alignment: function alignment(value) {
30
+ return _constants.ALIGNMENT_VALUES.includes(value);
31
+ }
32
+ };
33
+ var parseFromDefault = function parseFromDefault(defaultValue, value) {
34
+ if (typeof defaultValue === 'boolean') {
35
+ if (typeof value === 'boolean') {
36
+ return value;
37
+ }
38
+ if (value === 'true') {
39
+ return true;
40
+ }
41
+ if (value === 'false') {
42
+ return false;
43
+ }
44
+ return undefined;
45
+ }
46
+ if (typeof defaultValue === 'number') {
47
+ var parsed = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
48
+ return Number.isFinite(parsed) ? parsed : undefined;
49
+ }
50
+
51
+ // String-like values (including keys whose default is undefined, e.g. url/width)
52
+ return typeof value === 'string' ? value : undefined;
53
+ };
54
+ var serializeParameterValue = function serializeParameterValue(key, value) {
55
+ var validator = PARAMETER_VALIDATORS[key];
56
+ if (validator && !validator(value)) {
57
+ return undefined;
58
+ }
59
+ return value === undefined ? undefined : String(value);
60
+ };
61
+ var deserializeParameterValue = function deserializeParameterValue(key, value) {
62
+ var parsedValue = parseFromDefault(_constants.NATIVE_EMBED_PARAMETER_DEFAULTS[key], value);
63
+ var validator = PARAMETER_VALIDATORS[key];
64
+ if (parsedValue === undefined) {
65
+ return undefined;
66
+ }
67
+ if (validator && !validator(parsedValue)) {
68
+ return undefined;
69
+ }
70
+ return parsedValue;
71
+ };
72
+
13
73
  /**
14
- * Generic utility to update parameters on a native embed extension node.
15
- * Preserves existing parameters and merges in the new ones.
74
+ * Reads a value from extension parameters.macroParams by key.
75
+ * Supports both wrapped ({ value }) and unwrapped values.
16
76
  */
17
- function updateParameters(current, parameterUpdates) {
18
- var existingParams = current.attrs && 'parameters' in current.attrs && (0, _typeof2.default)(current.attrs.parameters) === 'object' ? current.attrs.parameters : {};
19
- return {
20
- attrs: _objectSpread(_objectSpread({}, current.attrs), {}, {
21
- parameters: _objectSpread(_objectSpread({}, existingParams), parameterUpdates)
22
- })
23
- };
77
+ var getParameter = exports.getParameter = function getParameter(parameters, key) {
78
+ var macroParams = getMacroParamsRecord(parameters);
79
+ if (!(key in macroParams)) {
80
+ return _constants.NATIVE_EMBED_PARAMETER_DEFAULTS[key];
81
+ }
82
+ var value = unwrapMacroParamValue(macroParams[key]);
83
+ var parsedValue = deserializeParameterValue(key, value);
84
+ return parsedValue === undefined ? _constants.NATIVE_EMBED_PARAMETER_DEFAULTS[key] : parsedValue;
85
+ };
86
+
87
+ /**
88
+ * Gets native-embed parameters as resolved values.
89
+ * When key is provided, returns that single resolved value.
90
+ * When key is omitted, returns all resolved parameter values.
91
+ */
92
+
93
+ function getParameters(parameters, key) {
94
+ if (key) {
95
+ return getParameter(parameters, key);
96
+ }
97
+ return Object.fromEntries(Object.keys(_constants.NATIVE_EMBED_PARAMETER_DEFAULTS).map(function (defaultKey) {
98
+ return [defaultKey, getParameter(parameters, defaultKey)];
99
+ }));
24
100
  }
25
101
 
102
+ /**
103
+ * Sets a single key in parameters.macroParams using wrapped { value } format.
104
+ * Returns a new parameters object.
105
+ */
106
+ var setParameter = exports.setParameter = function setParameter(parameters, update) {
107
+ return setParameters(parameters, update);
108
+ };
109
+
110
+ /**
111
+ * Sets multiple keys in parameters.macroParams using wrapped { value } format.
112
+ * Returns a new parameters object.
113
+ */
114
+ var setParameters = exports.setParameters = function setParameters(parameters, updates) {
115
+ var currentParameters = parameters !== null && parameters !== void 0 ? parameters : {};
116
+ var currentMacroParams = getMacroParamsRecord(parameters);
117
+ var wrappedUpdates = Object.fromEntries(Object.entries(updates).map(function (_ref) {
118
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
119
+ key = _ref2[0],
120
+ value = _ref2[1];
121
+ return [key, serializeParameterValue(key, value)];
122
+ }).filter(function (_ref3) {
123
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
124
+ value = _ref4[1];
125
+ return value !== undefined;
126
+ }).map(function (_ref5) {
127
+ var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
128
+ key = _ref6[0],
129
+ value = _ref6[1];
130
+ return [key, {
131
+ value: value
132
+ }];
133
+ }));
134
+ return _objectSpread(_objectSpread({}, currentParameters), {}, {
135
+ macroParams: _objectSpread(_objectSpread({}, currentMacroParams), wrappedUpdates)
136
+ });
137
+ };
138
+
26
139
  /**
27
140
  * Helper function to create a type-safe ManifestEditorToolbarActions config.
28
141
  * Automatically infers custom action keys from the customActions object.
@@ -36,6 +149,12 @@ function updateParameters(current, parameterUpdates) {
36
149
  * items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
37
150
  * moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
38
151
  * });
152
+ *
153
+ * // Or without custom actions:
154
+ * const simpleConfig = createEditorToolbarActions({
155
+ * items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
156
+ * moreItems: ['delete'],
157
+ * });
39
158
  * ```
40
159
  */
41
160
  var createEditorToolbarActions = exports.createEditorToolbarActions = function createEditorToolbarActions(config) {
@@ -1,7 +1,9 @@
1
1
  // Re-export constants
2
- export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS } from './utils/constants';
2
+ export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS } from './utils/constants';
3
3
 
4
4
  // Re-export types
5
5
 
6
+ // Plugin actions types
7
+
6
8
  // Re-export utilities
7
- export { updateParameters, createEditorToolbarActions } from './utils/utils';
9
+ export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters } from './utils/utils';
@@ -1,23 +1,35 @@
1
1
  // Alignment constants
2
2
  export const ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
3
3
  export const DEFAULT_ALIGNMENT = 'center';
4
+ export const NATIVE_EMBED_PARAMETER_DEFAULTS = {
5
+ url: undefined,
6
+ alwaysShowTitle: false,
7
+ alignment: DEFAULT_ALIGNMENT,
8
+ displayText: undefined,
9
+ height: 600,
10
+ width: undefined
11
+ };
4
12
 
5
13
  /**
6
14
  * Built-in keys that can be referenced in the `items` and `moreItems` arrays.
7
15
  *
8
- * Toolbar keys: REFRESH, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
16
+ * Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
9
17
  * More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
10
18
  * Shared: SEPARATOR (usable in both)
11
19
  */
12
20
  export const BUILTIN_TOOLBAR_KEYS = {
21
+ ASK_ROVO: 'askRovo',
13
22
  REFRESH: 'refresh',
23
+ EDIT: 'edit',
14
24
  EMBED: 'embed',
15
25
  BORDER: 'border',
16
26
  ALIGNMENT: 'alignment',
17
27
  OPEN_IN_NEW_WINDOW: 'openInNewWindow',
28
+ EDIT_URL: 'editUrl',
18
29
  ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
19
30
  SET_EMBED_TYPE: 'setEmbedType',
20
31
  COPY_LINK: 'copyLink',
21
32
  DELETE: 'delete',
22
33
  SEPARATOR: 'separator'
23
- };
34
+ };
35
+ export const EDITOR_TOOLBAR_HANDLER_KEYS = ['onAlignmentClick', 'onAppearanceClick', 'onAskRovoClick', 'onCopyLinkClick', 'onChangeBorderClick', 'onDeleteClick', 'onEditUrlClick', 'onEditClick', 'onOpenInNewWindowClick', 'onRefreshClick', 'onSetEmbedTypeClick', 'onShowTitleClick'];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,112 @@
1
+ import { ALIGNMENT_VALUES, NATIVE_EMBED_PARAMETER_DEFAULTS } from './constants';
2
+ const getMacroParamsRecord = parameters => {
3
+ if (!(parameters !== null && parameters !== void 0 && parameters.macroParams) || typeof parameters.macroParams !== 'object') {
4
+ return {};
5
+ }
6
+ return parameters.macroParams;
7
+ };
8
+ const unwrapMacroParamValue = macroParamValue => {
9
+ if (macroParamValue && typeof macroParamValue === 'object' && 'value' in macroParamValue) {
10
+ return macroParamValue.value;
11
+ }
12
+ return macroParamValue;
13
+ };
14
+ const PARAMETER_VALIDATORS = {
15
+ alignment: value => ALIGNMENT_VALUES.includes(value)
16
+ };
17
+ const parseFromDefault = (defaultValue, value) => {
18
+ if (typeof defaultValue === 'boolean') {
19
+ if (typeof value === 'boolean') {
20
+ return value;
21
+ }
22
+ if (value === 'true') {
23
+ return true;
24
+ }
25
+ if (value === 'false') {
26
+ return false;
27
+ }
28
+ return undefined;
29
+ }
30
+ if (typeof defaultValue === 'number') {
31
+ const parsed = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
32
+ return Number.isFinite(parsed) ? parsed : undefined;
33
+ }
34
+
35
+ // String-like values (including keys whose default is undefined, e.g. url/width)
36
+ return typeof value === 'string' ? value : undefined;
37
+ };
38
+ const serializeParameterValue = (key, value) => {
39
+ const validator = PARAMETER_VALIDATORS[key];
40
+ if (validator && !validator(value)) {
41
+ return undefined;
42
+ }
43
+ return value === undefined ? undefined : String(value);
44
+ };
45
+ const deserializeParameterValue = (key, value) => {
46
+ const parsedValue = parseFromDefault(NATIVE_EMBED_PARAMETER_DEFAULTS[key], value);
47
+ const validator = PARAMETER_VALIDATORS[key];
48
+ if (parsedValue === undefined) {
49
+ return undefined;
50
+ }
51
+ if (validator && !validator(parsedValue)) {
52
+ return undefined;
53
+ }
54
+ return parsedValue;
55
+ };
56
+
1
57
  /**
2
- * Generic utility to update parameters on a native embed extension node.
3
- * Preserves existing parameters and merges in the new ones.
58
+ * Reads a value from extension parameters.macroParams by key.
59
+ * Supports both wrapped ({ value }) and unwrapped values.
4
60
  */
5
- export function updateParameters(current, parameterUpdates) {
6
- const existingParams = current.attrs && 'parameters' in current.attrs && typeof current.attrs.parameters === 'object' ? current.attrs.parameters : {};
61
+ export const getParameter = (parameters, key) => {
62
+ const macroParams = getMacroParamsRecord(parameters);
63
+ if (!(key in macroParams)) {
64
+ return NATIVE_EMBED_PARAMETER_DEFAULTS[key];
65
+ }
66
+ const value = unwrapMacroParamValue(macroParams[key]);
67
+ const parsedValue = deserializeParameterValue(key, value);
68
+ return parsedValue === undefined ? NATIVE_EMBED_PARAMETER_DEFAULTS[key] : parsedValue;
69
+ };
70
+
71
+ /**
72
+ * Gets native-embed parameters as resolved values.
73
+ * When key is provided, returns that single resolved value.
74
+ * When key is omitted, returns all resolved parameter values.
75
+ */
76
+
77
+ export function getParameters(parameters, key) {
78
+ if (key) {
79
+ return getParameter(parameters, key);
80
+ }
81
+ return Object.fromEntries(Object.keys(NATIVE_EMBED_PARAMETER_DEFAULTS).map(defaultKey => [defaultKey, getParameter(parameters, defaultKey)]));
82
+ }
83
+
84
+ /**
85
+ * Sets a single key in parameters.macroParams using wrapped { value } format.
86
+ * Returns a new parameters object.
87
+ */
88
+ export const setParameter = (parameters, update) => {
89
+ return setParameters(parameters, update);
90
+ };
91
+
92
+ /**
93
+ * Sets multiple keys in parameters.macroParams using wrapped { value } format.
94
+ * Returns a new parameters object.
95
+ */
96
+ export const setParameters = (parameters, updates) => {
97
+ const currentParameters = parameters !== null && parameters !== void 0 ? parameters : {};
98
+ const currentMacroParams = getMacroParamsRecord(parameters);
99
+ const wrappedUpdates = Object.fromEntries(Object.entries(updates).map(([key, value]) => [key, serializeParameterValue(key, value)]).filter(([, value]) => value !== undefined).map(([key, value]) => [key, {
100
+ value
101
+ }]));
7
102
  return {
8
- attrs: {
9
- ...current.attrs,
10
- parameters: {
11
- ...existingParams,
12
- ...parameterUpdates
13
- }
103
+ ...currentParameters,
104
+ macroParams: {
105
+ ...currentMacroParams,
106
+ ...wrappedUpdates
14
107
  }
15
108
  };
16
- }
109
+ };
17
110
 
18
111
  /**
19
112
  * Helper function to create a type-safe ManifestEditorToolbarActions config.
@@ -28,6 +121,12 @@ export function updateParameters(current, parameterUpdates) {
28
121
  * items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
29
122
  * moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
30
123
  * });
124
+ *
125
+ * // Or without custom actions:
126
+ * const simpleConfig = createEditorToolbarActions({
127
+ * items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
128
+ * moreItems: ['delete'],
129
+ * });
31
130
  * ```
32
131
  */
33
132
  export const createEditorToolbarActions = config => config;
package/dist/esm/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // Re-export constants
2
- export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS } from './utils/constants';
2
+ export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS } from './utils/constants';
3
3
 
4
4
  // Re-export types
5
5
 
6
+ // Plugin actions types
7
+
6
8
  // Re-export utilities
7
- export { updateParameters, createEditorToolbarActions } from './utils/utils';
9
+ export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters } from './utils/utils';
@@ -1,23 +1,35 @@
1
1
  // Alignment constants
2
2
  export var ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
3
3
  export var DEFAULT_ALIGNMENT = 'center';
4
+ export var NATIVE_EMBED_PARAMETER_DEFAULTS = {
5
+ url: undefined,
6
+ alwaysShowTitle: false,
7
+ alignment: DEFAULT_ALIGNMENT,
8
+ displayText: undefined,
9
+ height: 600,
10
+ width: undefined
11
+ };
4
12
 
5
13
  /**
6
14
  * Built-in keys that can be referenced in the `items` and `moreItems` arrays.
7
15
  *
8
- * Toolbar keys: REFRESH, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
16
+ * Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
9
17
  * More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
10
18
  * Shared: SEPARATOR (usable in both)
11
19
  */
12
20
  export var BUILTIN_TOOLBAR_KEYS = {
21
+ ASK_ROVO: 'askRovo',
13
22
  REFRESH: 'refresh',
23
+ EDIT: 'edit',
14
24
  EMBED: 'embed',
15
25
  BORDER: 'border',
16
26
  ALIGNMENT: 'alignment',
17
27
  OPEN_IN_NEW_WINDOW: 'openInNewWindow',
28
+ EDIT_URL: 'editUrl',
18
29
  ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
19
30
  SET_EMBED_TYPE: 'setEmbedType',
20
31
  COPY_LINK: 'copyLink',
21
32
  DELETE: 'delete',
22
33
  SEPARATOR: 'separator'
23
- };
34
+ };
35
+ export var EDITOR_TOOLBAR_HANDLER_KEYS = ['onAlignmentClick', 'onAppearanceClick', 'onAskRovoClick', 'onCopyLinkClick', 'onChangeBorderClick', 'onDeleteClick', 'onEditUrlClick', 'onEditClick', 'onOpenInNewWindowClick', 'onRefreshClick', 'onSetEmbedTypeClick', 'onShowTitleClick'];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,20 +1,132 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import _typeof from "@babel/runtime/helpers/typeof";
3
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ import { ALIGNMENT_VALUES, NATIVE_EMBED_PARAMETER_DEFAULTS } from './constants';
7
+ var getMacroParamsRecord = function getMacroParamsRecord(parameters) {
8
+ if (!(parameters !== null && parameters !== void 0 && parameters.macroParams) || _typeof(parameters.macroParams) !== 'object') {
9
+ return {};
10
+ }
11
+ return parameters.macroParams;
12
+ };
13
+ var unwrapMacroParamValue = function unwrapMacroParamValue(macroParamValue) {
14
+ if (macroParamValue && _typeof(macroParamValue) === 'object' && 'value' in macroParamValue) {
15
+ return macroParamValue.value;
16
+ }
17
+ return macroParamValue;
18
+ };
19
+ var PARAMETER_VALIDATORS = {
20
+ alignment: function alignment(value) {
21
+ return ALIGNMENT_VALUES.includes(value);
22
+ }
23
+ };
24
+ var parseFromDefault = function parseFromDefault(defaultValue, value) {
25
+ if (typeof defaultValue === 'boolean') {
26
+ if (typeof value === 'boolean') {
27
+ return value;
28
+ }
29
+ if (value === 'true') {
30
+ return true;
31
+ }
32
+ if (value === 'false') {
33
+ return false;
34
+ }
35
+ return undefined;
36
+ }
37
+ if (typeof defaultValue === 'number') {
38
+ var parsed = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
39
+ return Number.isFinite(parsed) ? parsed : undefined;
40
+ }
41
+
42
+ // String-like values (including keys whose default is undefined, e.g. url/width)
43
+ return typeof value === 'string' ? value : undefined;
44
+ };
45
+ var serializeParameterValue = function serializeParameterValue(key, value) {
46
+ var validator = PARAMETER_VALIDATORS[key];
47
+ if (validator && !validator(value)) {
48
+ return undefined;
49
+ }
50
+ return value === undefined ? undefined : String(value);
51
+ };
52
+ var deserializeParameterValue = function deserializeParameterValue(key, value) {
53
+ var parsedValue = parseFromDefault(NATIVE_EMBED_PARAMETER_DEFAULTS[key], value);
54
+ var validator = PARAMETER_VALIDATORS[key];
55
+ if (parsedValue === undefined) {
56
+ return undefined;
57
+ }
58
+ if (validator && !validator(parsedValue)) {
59
+ return undefined;
60
+ }
61
+ return parsedValue;
62
+ };
63
+
5
64
  /**
6
- * Generic utility to update parameters on a native embed extension node.
7
- * Preserves existing parameters and merges in the new ones.
65
+ * Reads a value from extension parameters.macroParams by key.
66
+ * Supports both wrapped ({ value }) and unwrapped values.
8
67
  */
9
- export function updateParameters(current, parameterUpdates) {
10
- var existingParams = current.attrs && 'parameters' in current.attrs && _typeof(current.attrs.parameters) === 'object' ? current.attrs.parameters : {};
11
- return {
12
- attrs: _objectSpread(_objectSpread({}, current.attrs), {}, {
13
- parameters: _objectSpread(_objectSpread({}, existingParams), parameterUpdates)
14
- })
15
- };
68
+ export var getParameter = function getParameter(parameters, key) {
69
+ var macroParams = getMacroParamsRecord(parameters);
70
+ if (!(key in macroParams)) {
71
+ return NATIVE_EMBED_PARAMETER_DEFAULTS[key];
72
+ }
73
+ var value = unwrapMacroParamValue(macroParams[key]);
74
+ var parsedValue = deserializeParameterValue(key, value);
75
+ return parsedValue === undefined ? NATIVE_EMBED_PARAMETER_DEFAULTS[key] : parsedValue;
76
+ };
77
+
78
+ /**
79
+ * Gets native-embed parameters as resolved values.
80
+ * When key is provided, returns that single resolved value.
81
+ * When key is omitted, returns all resolved parameter values.
82
+ */
83
+
84
+ export function getParameters(parameters, key) {
85
+ if (key) {
86
+ return getParameter(parameters, key);
87
+ }
88
+ return Object.fromEntries(Object.keys(NATIVE_EMBED_PARAMETER_DEFAULTS).map(function (defaultKey) {
89
+ return [defaultKey, getParameter(parameters, defaultKey)];
90
+ }));
16
91
  }
17
92
 
93
+ /**
94
+ * Sets a single key in parameters.macroParams using wrapped { value } format.
95
+ * Returns a new parameters object.
96
+ */
97
+ export var setParameter = function setParameter(parameters, update) {
98
+ return setParameters(parameters, update);
99
+ };
100
+
101
+ /**
102
+ * Sets multiple keys in parameters.macroParams using wrapped { value } format.
103
+ * Returns a new parameters object.
104
+ */
105
+ export var setParameters = function setParameters(parameters, updates) {
106
+ var currentParameters = parameters !== null && parameters !== void 0 ? parameters : {};
107
+ var currentMacroParams = getMacroParamsRecord(parameters);
108
+ var wrappedUpdates = Object.fromEntries(Object.entries(updates).map(function (_ref) {
109
+ var _ref2 = _slicedToArray(_ref, 2),
110
+ key = _ref2[0],
111
+ value = _ref2[1];
112
+ return [key, serializeParameterValue(key, value)];
113
+ }).filter(function (_ref3) {
114
+ var _ref4 = _slicedToArray(_ref3, 2),
115
+ value = _ref4[1];
116
+ return value !== undefined;
117
+ }).map(function (_ref5) {
118
+ var _ref6 = _slicedToArray(_ref5, 2),
119
+ key = _ref6[0],
120
+ value = _ref6[1];
121
+ return [key, {
122
+ value: value
123
+ }];
124
+ }));
125
+ return _objectSpread(_objectSpread({}, currentParameters), {}, {
126
+ macroParams: _objectSpread(_objectSpread({}, currentMacroParams), wrappedUpdates)
127
+ });
128
+ };
129
+
18
130
  /**
19
131
  * Helper function to create a type-safe ManifestEditorToolbarActions config.
20
132
  * Automatically infers custom action keys from the customActions object.
@@ -28,6 +140,12 @@ export function updateParameters(current, parameterUpdates) {
28
140
  * items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
29
141
  * moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
30
142
  * });
143
+ *
144
+ * // Or without custom actions:
145
+ * const simpleConfig = createEditorToolbarActions({
146
+ * items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
147
+ * moreItems: ['delete'],
148
+ * });
31
149
  * ```
32
150
  */
33
151
  export var createEditorToolbarActions = function createEditorToolbarActions(config) {
@@ -1,3 +1,4 @@
1
- export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS } from './utils/constants';
2
- export type { AlignmentValue, EditorToolbarButtonAction, EditorToolbarAction, BuiltinToolbarKey, ManifestEditorToolbarActions, } from './utils/types';
3
- export { updateParameters, createEditorToolbarActions } from './utils/utils';
1
+ export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS, } from './utils/constants';
2
+ export type { AlignmentValue, EditorToolbarButtonAction, EditorToolbarAction, EditorToolbarHandler, EditorToolbarHandlerContext, EditorToolbarHandlerKey, EditorToolbarHandlers, NativeEmbedAppearance, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameterValue, NativeEmbedParameters, BuiltinToolbarKey, ManifestEditorToolbarActions, } from './utils/types';
3
+ export type { CardToNativeEmbedNode, CardToNativeEmbedTransformOptions, CreateCardToNativeEmbedTransform, EditorPluginNativeEmbedsPlugin, NativeEmbedLayout, NativeEmbedTransformAttrs, } from './utils/plugin-actions/types';
4
+ export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters, } from './utils/utils';
@@ -1,21 +1,27 @@
1
+ import type { NativeEmbedParameterValues } from './types';
1
2
  export declare const ALIGNMENT_VALUES: readonly ["left", "center", "right", "wrap-left", "wrap-right"];
2
3
  export declare const DEFAULT_ALIGNMENT: "center";
4
+ export declare const NATIVE_EMBED_PARAMETER_DEFAULTS: NativeEmbedParameterValues;
3
5
  /**
4
6
  * Built-in keys that can be referenced in the `items` and `moreItems` arrays.
5
7
  *
6
- * Toolbar keys: REFRESH, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
8
+ * Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
7
9
  * More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
8
10
  * Shared: SEPARATOR (usable in both)
9
11
  */
10
12
  export declare const BUILTIN_TOOLBAR_KEYS: {
13
+ readonly ASK_ROVO: "askRovo";
11
14
  readonly REFRESH: "refresh";
15
+ readonly EDIT: "edit";
12
16
  readonly EMBED: "embed";
13
17
  readonly BORDER: "border";
14
18
  readonly ALIGNMENT: "alignment";
15
19
  readonly OPEN_IN_NEW_WINDOW: "openInNewWindow";
20
+ readonly EDIT_URL: "editUrl";
16
21
  readonly ALWAYS_SHOW_TITLE: "alwaysShowTitle";
17
22
  readonly SET_EMBED_TYPE: "setEmbedType";
18
23
  readonly COPY_LINK: "copyLink";
19
24
  readonly DELETE: "delete";
20
25
  readonly SEPARATOR: "separator";
21
26
  };
27
+ export declare const EDITOR_TOOLBAR_HANDLER_KEYS: readonly ["onAlignmentClick", "onAppearanceClick", "onAskRovoClick", "onCopyLinkClick", "onChangeBorderClick", "onDeleteClick", "onEditUrlClick", "onEditClick", "onOpenInNewWindowClick", "onRefreshClick", "onSetEmbedTypeClick", "onShowTitleClick"];
@@ -0,0 +1,33 @@
1
+ import type { Command, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ import type { Node, Schema } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ /** Accepted layout values from ADF schema (embedCard) */
5
+ export type NativeEmbedLayout = 'wide' | 'full-width' | 'center' | 'wrap-right' | 'wrap-left' | 'align-end' | 'align-start';
6
+ /** Input attrs for embedCard node (subset used by transform) */
7
+ export interface NativeEmbedTransformAttrs {
8
+ layout?: NativeEmbedLayout;
9
+ originalHeight?: number | null;
10
+ originalWidth?: number | null;
11
+ url: string;
12
+ width?: number;
13
+ }
14
+ /** Type for cardToNativeEmbedNode - converts embed attrs to native embed Node */
15
+ export type CardToNativeEmbedNode = (schema: Schema, attrs: NativeEmbedTransformAttrs) => Node | undefined;
16
+ /** Type for createEmbedCardToNativeEmbedTransform - returns a Command */
17
+ export type CreateCardToNativeEmbedTransform = (options?: CardToNativeEmbedTransformOptions) => Command;
18
+ export interface CardToNativeEmbedTransformOptions {
19
+ /**
20
+ * Called before dispatch to allow the caller to augment the transaction
21
+ * (e.g. datasource stash, analytics, link metadata).
22
+ */
23
+ augmentTransaction?: (tr: Transaction, state: EditorState) => void;
24
+ }
25
+ /**
26
+ * Minimal plugin type for native embeds action integration.
27
+ */
28
+ export type EditorPluginNativeEmbedsPlugin = NextEditorPlugin<'editorPluginNativeEmbeds', {
29
+ actions: {
30
+ cardToNativeEmbedNode: CardToNativeEmbedNode;
31
+ createCardToNativeEmbedTransform: CreateCardToNativeEmbedTransform;
32
+ };
33
+ }>;
@@ -1,7 +1,34 @@
1
1
  import type { ComponentType } from 'react';
2
+ import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
2
3
  import type { NewCoreIconProps } from '@atlaskit/icon';
3
- import type { ALIGNMENT_VALUES, BUILTIN_TOOLBAR_KEYS } from './constants';
4
- export type AlignmentValue = (typeof ALIGNMENT_VALUES)[number];
4
+ import type { BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS } from './constants';
5
+ export type AlignmentValue = 'left' | 'center' | 'right' | 'wrap-left' | 'wrap-right';
6
+ export type NativeEmbedAppearance = 'url' | 'inline' | 'block' | 'embed';
7
+ export type NativeEmbedParameterValues = {
8
+ alignment: AlignmentValue;
9
+ alwaysShowTitle: boolean;
10
+ displayText?: string;
11
+ height: number;
12
+ url?: string;
13
+ width?: number;
14
+ };
15
+ export type NativeEmbedParameterValue = {
16
+ value: string;
17
+ };
18
+ export type NativeEmbedParameters = {
19
+ macroParams?: {
20
+ alignment?: NativeEmbedParameterValue;
21
+ alwaysShowTitle?: NativeEmbedParameterValue;
22
+ displayText?: NativeEmbedParameterValue;
23
+ height?: NativeEmbedParameterValue;
24
+ url?: NativeEmbedParameterValue;
25
+ width?: NativeEmbedParameterValue;
26
+ };
27
+ };
28
+ export type NativeEmbedParameterKey = keyof NonNullable<NativeEmbedParameters['macroParams']>;
29
+ export type EditorToolbarHandlerContext = {
30
+ editorApi?: PublicPluginAPI<[]>;
31
+ };
5
32
  /**
6
33
  * A button action rendered in the editor floating toolbar.
7
34
  */
@@ -40,6 +67,30 @@ export type EditorToolbarButtonAction = {
40
67
  * Currently only supports buttons; dropdowns and separators can be added later.
41
68
  */
42
69
  export type EditorToolbarAction = EditorToolbarButtonAction;
70
+ /**
71
+ * Handlers for built-in native embed floating toolbar actions.
72
+ * Can be defined in the manifest (editorToolbarHandlers) and are invoked
73
+ * by the editor plugin when the corresponding toolbar buttons are clicked.
74
+ * Handlers with context (e.g. onAlignmentClick, onAppearanceClick) receive
75
+ * an optional second parameter for the action-specific value.
76
+ */
77
+ export type EditorToolbarHandlerKey = (typeof EDITOR_TOOLBAR_HANDLER_KEYS)[number];
78
+ export type EditorToolbarHandlers = Partial<{
79
+ onAlignmentClick: (parameters: NativeEmbedParameterValues, alignment: AlignmentValue, context?: EditorToolbarHandlerContext) => void;
80
+ onAppearanceClick: (parameters: NativeEmbedParameterValues, appearance: NativeEmbedAppearance, context?: EditorToolbarHandlerContext) => void;
81
+ onAskRovoClick: (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
82
+ onChangeBorderClick: EditorToolbarHandler;
83
+ onCopyLinkClick: EditorToolbarHandler;
84
+ onDeleteClick: EditorToolbarHandler;
85
+ onEditClick: EditorToolbarHandler;
86
+ onEditUrlClick: EditorToolbarHandler;
87
+ onOpenInNewWindowClick: EditorToolbarHandler;
88
+ onRefreshClick: EditorToolbarHandler;
89
+ onSetEmbedTypeClick: EditorToolbarHandler;
90
+ onShowTitleClick: EditorToolbarHandler;
91
+ }>;
92
+ /** Base handler signature for contexts that don't have action-specific context. */
93
+ export type EditorToolbarHandler = (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
43
94
  export type BuiltinToolbarKey = (typeof BUILTIN_TOOLBAR_KEYS)[keyof typeof BUILTIN_TOOLBAR_KEYS];
44
95
  /**
45
96
  * Configuration for editor toolbar actions in the manifest.
@@ -55,6 +106,12 @@ export type ManifestEditorToolbarActions<TCustomActions extends Record<string, E
55
106
  * These can be referenced in the `items` array alongside built-in keys.
56
107
  */
57
108
  customActions?: TCustomActions;
109
+ /**
110
+ * Handlers for built-in toolbar buttons.
111
+ * When a built-in button (e.g. ASK_ROVO, REFRESH) is clicked, the corresponding
112
+ * handler is invoked by the editor plugin.
113
+ */
114
+ editorToolbarHandlers?: EditorToolbarHandlers;
58
115
  /**
59
116
  * Ordered array of keys specifying which toolbar items to show and in what order.
60
117
  * The "More Options" dropdown is appended automatically based on `moreItems`.
@@ -1,13 +1,26 @@
1
- import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey } from './types';
1
+ import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameters } from './types';
2
2
  /**
3
- * Generic utility to update parameters on a native embed extension node.
4
- * Preserves existing parameters and merges in the new ones.
3
+ * Reads a value from extension parameters.macroParams by key.
4
+ * Supports both wrapped ({ value }) and unwrapped values.
5
5
  */
6
- export declare function updateParameters(current: {
7
- attrs?: Record<string, unknown>;
8
- }, parameterUpdates: Record<string, unknown>): {
9
- attrs: Record<string, unknown>;
10
- };
6
+ export declare const getParameter: <TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, key: TKey) => NativeEmbedParameterValues[TKey];
7
+ /**
8
+ * Gets native-embed parameters as resolved values.
9
+ * When key is provided, returns that single resolved value.
10
+ * When key is omitted, returns all resolved parameter values.
11
+ */
12
+ export declare function getParameters(parameters: NativeEmbedParameters | undefined): NativeEmbedParameterValues;
13
+ export declare function getParameters<TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, key: TKey): NativeEmbedParameterValues[TKey];
14
+ /**
15
+ * Sets a single key in parameters.macroParams using wrapped { value } format.
16
+ * Returns a new parameters object.
17
+ */
18
+ export declare const setParameter: <TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, update: Pick<NativeEmbedParameterValues, TKey>) => NativeEmbedParameters;
19
+ /**
20
+ * Sets multiple keys in parameters.macroParams using wrapped { value } format.
21
+ * Returns a new parameters object.
22
+ */
23
+ export declare const setParameters: (parameters: NativeEmbedParameters | undefined, updates: Partial<NativeEmbedParameterValues>) => NativeEmbedParameters;
11
24
  /**
12
25
  * Helper function to create a type-safe ManifestEditorToolbarActions config.
13
26
  * Automatically infers custom action keys from the customActions object.
@@ -21,10 +34,16 @@ export declare function updateParameters(current: {
21
34
  * items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
22
35
  * moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
23
36
  * });
37
+ *
38
+ * // Or without custom actions:
39
+ * const simpleConfig = createEditorToolbarActions({
40
+ * items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
41
+ * moreItems: ['delete'],
42
+ * });
24
43
  * ```
25
44
  */
26
- export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction>>(config: {
27
- customActions: TCustomActions;
45
+ export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>>(config: {
46
+ customActions?: TCustomActions;
28
47
  items: (BuiltinToolbarKey | keyof TCustomActions)[];
29
48
  moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
30
49
  }) => ManifestEditorToolbarActions<TCustomActions>;
@@ -1,3 +1,4 @@
1
- export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS } from './utils/constants';
2
- export type { AlignmentValue, EditorToolbarButtonAction, EditorToolbarAction, BuiltinToolbarKey, ManifestEditorToolbarActions, } from './utils/types';
3
- export { updateParameters, createEditorToolbarActions } from './utils/utils';
1
+ export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS, } from './utils/constants';
2
+ export type { AlignmentValue, EditorToolbarButtonAction, EditorToolbarAction, EditorToolbarHandler, EditorToolbarHandlerContext, EditorToolbarHandlerKey, EditorToolbarHandlers, NativeEmbedAppearance, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameterValue, NativeEmbedParameters, BuiltinToolbarKey, ManifestEditorToolbarActions, } from './utils/types';
3
+ export type { CardToNativeEmbedNode, CardToNativeEmbedTransformOptions, CreateCardToNativeEmbedTransform, EditorPluginNativeEmbedsPlugin, NativeEmbedLayout, NativeEmbedTransformAttrs, } from './utils/plugin-actions/types';
4
+ export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters, } from './utils/utils';
@@ -1,3 +1,4 @@
1
+ import type { NativeEmbedParameterValues } from './types';
1
2
  export declare const ALIGNMENT_VALUES: readonly [
2
3
  "left",
3
4
  "center",
@@ -6,22 +7,40 @@ export declare const ALIGNMENT_VALUES: readonly [
6
7
  "wrap-right"
7
8
  ];
8
9
  export declare const DEFAULT_ALIGNMENT: "center";
10
+ export declare const NATIVE_EMBED_PARAMETER_DEFAULTS: NativeEmbedParameterValues;
9
11
  /**
10
12
  * Built-in keys that can be referenced in the `items` and `moreItems` arrays.
11
13
  *
12
- * Toolbar keys: REFRESH, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
14
+ * Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
13
15
  * More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
14
16
  * Shared: SEPARATOR (usable in both)
15
17
  */
16
18
  export declare const BUILTIN_TOOLBAR_KEYS: {
19
+ readonly ASK_ROVO: "askRovo";
17
20
  readonly REFRESH: "refresh";
21
+ readonly EDIT: "edit";
18
22
  readonly EMBED: "embed";
19
23
  readonly BORDER: "border";
20
24
  readonly ALIGNMENT: "alignment";
21
25
  readonly OPEN_IN_NEW_WINDOW: "openInNewWindow";
26
+ readonly EDIT_URL: "editUrl";
22
27
  readonly ALWAYS_SHOW_TITLE: "alwaysShowTitle";
23
28
  readonly SET_EMBED_TYPE: "setEmbedType";
24
29
  readonly COPY_LINK: "copyLink";
25
30
  readonly DELETE: "delete";
26
31
  readonly SEPARATOR: "separator";
27
32
  };
33
+ export declare const EDITOR_TOOLBAR_HANDLER_KEYS: readonly [
34
+ "onAlignmentClick",
35
+ "onAppearanceClick",
36
+ "onAskRovoClick",
37
+ "onCopyLinkClick",
38
+ "onChangeBorderClick",
39
+ "onDeleteClick",
40
+ "onEditUrlClick",
41
+ "onEditClick",
42
+ "onOpenInNewWindowClick",
43
+ "onRefreshClick",
44
+ "onSetEmbedTypeClick",
45
+ "onShowTitleClick"
46
+ ];
@@ -0,0 +1,33 @@
1
+ import type { Command, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ import type { Node, Schema } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ /** Accepted layout values from ADF schema (embedCard) */
5
+ export type NativeEmbedLayout = 'wide' | 'full-width' | 'center' | 'wrap-right' | 'wrap-left' | 'align-end' | 'align-start';
6
+ /** Input attrs for embedCard node (subset used by transform) */
7
+ export interface NativeEmbedTransformAttrs {
8
+ layout?: NativeEmbedLayout;
9
+ originalHeight?: number | null;
10
+ originalWidth?: number | null;
11
+ url: string;
12
+ width?: number;
13
+ }
14
+ /** Type for cardToNativeEmbedNode - converts embed attrs to native embed Node */
15
+ export type CardToNativeEmbedNode = (schema: Schema, attrs: NativeEmbedTransformAttrs) => Node | undefined;
16
+ /** Type for createEmbedCardToNativeEmbedTransform - returns a Command */
17
+ export type CreateCardToNativeEmbedTransform = (options?: CardToNativeEmbedTransformOptions) => Command;
18
+ export interface CardToNativeEmbedTransformOptions {
19
+ /**
20
+ * Called before dispatch to allow the caller to augment the transaction
21
+ * (e.g. datasource stash, analytics, link metadata).
22
+ */
23
+ augmentTransaction?: (tr: Transaction, state: EditorState) => void;
24
+ }
25
+ /**
26
+ * Minimal plugin type for native embeds action integration.
27
+ */
28
+ export type EditorPluginNativeEmbedsPlugin = NextEditorPlugin<'editorPluginNativeEmbeds', {
29
+ actions: {
30
+ cardToNativeEmbedNode: CardToNativeEmbedNode;
31
+ createCardToNativeEmbedTransform: CreateCardToNativeEmbedTransform;
32
+ };
33
+ }>;
@@ -1,7 +1,35 @@
1
1
  import type { ComponentType } from 'react';
2
+ import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
2
3
  import type { NewCoreIconProps } from '@atlaskit/icon';
3
- import type { ALIGNMENT_VALUES, BUILTIN_TOOLBAR_KEYS } from './constants';
4
- export type AlignmentValue = (typeof ALIGNMENT_VALUES)[number];
4
+ import type { BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS } from './constants';
5
+ export type AlignmentValue = 'left' | 'center' | 'right' | 'wrap-left' | 'wrap-right';
6
+ export type NativeEmbedAppearance = 'url' | 'inline' | 'block' | 'embed';
7
+ export type NativeEmbedParameterValues = {
8
+ alignment: AlignmentValue;
9
+ alwaysShowTitle: boolean;
10
+ displayText?: string;
11
+ height: number;
12
+ url?: string;
13
+ width?: number;
14
+ };
15
+ export type NativeEmbedParameterValue = {
16
+ value: string;
17
+ };
18
+ export type NativeEmbedParameters = {
19
+ macroParams?: {
20
+ alignment?: NativeEmbedParameterValue;
21
+ alwaysShowTitle?: NativeEmbedParameterValue;
22
+ displayText?: NativeEmbedParameterValue;
23
+ height?: NativeEmbedParameterValue;
24
+ url?: NativeEmbedParameterValue;
25
+ width?: NativeEmbedParameterValue;
26
+ };
27
+ };
28
+ export type NativeEmbedParameterKey = keyof NonNullable<NativeEmbedParameters['macroParams']>;
29
+ export type EditorToolbarHandlerContext = {
30
+ editorApi?: PublicPluginAPI<[
31
+ ]>;
32
+ };
5
33
  /**
6
34
  * A button action rendered in the editor floating toolbar.
7
35
  */
@@ -40,6 +68,30 @@ export type EditorToolbarButtonAction = {
40
68
  * Currently only supports buttons; dropdowns and separators can be added later.
41
69
  */
42
70
  export type EditorToolbarAction = EditorToolbarButtonAction;
71
+ /**
72
+ * Handlers for built-in native embed floating toolbar actions.
73
+ * Can be defined in the manifest (editorToolbarHandlers) and are invoked
74
+ * by the editor plugin when the corresponding toolbar buttons are clicked.
75
+ * Handlers with context (e.g. onAlignmentClick, onAppearanceClick) receive
76
+ * an optional second parameter for the action-specific value.
77
+ */
78
+ export type EditorToolbarHandlerKey = (typeof EDITOR_TOOLBAR_HANDLER_KEYS)[number];
79
+ export type EditorToolbarHandlers = Partial<{
80
+ onAlignmentClick: (parameters: NativeEmbedParameterValues, alignment: AlignmentValue, context?: EditorToolbarHandlerContext) => void;
81
+ onAppearanceClick: (parameters: NativeEmbedParameterValues, appearance: NativeEmbedAppearance, context?: EditorToolbarHandlerContext) => void;
82
+ onAskRovoClick: (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
83
+ onChangeBorderClick: EditorToolbarHandler;
84
+ onCopyLinkClick: EditorToolbarHandler;
85
+ onDeleteClick: EditorToolbarHandler;
86
+ onEditClick: EditorToolbarHandler;
87
+ onEditUrlClick: EditorToolbarHandler;
88
+ onOpenInNewWindowClick: EditorToolbarHandler;
89
+ onRefreshClick: EditorToolbarHandler;
90
+ onSetEmbedTypeClick: EditorToolbarHandler;
91
+ onShowTitleClick: EditorToolbarHandler;
92
+ }>;
93
+ /** Base handler signature for contexts that don't have action-specific context. */
94
+ export type EditorToolbarHandler = (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
43
95
  export type BuiltinToolbarKey = (typeof BUILTIN_TOOLBAR_KEYS)[keyof typeof BUILTIN_TOOLBAR_KEYS];
44
96
  /**
45
97
  * Configuration for editor toolbar actions in the manifest.
@@ -55,6 +107,12 @@ export type ManifestEditorToolbarActions<TCustomActions extends Record<string, E
55
107
  * These can be referenced in the `items` array alongside built-in keys.
56
108
  */
57
109
  customActions?: TCustomActions;
110
+ /**
111
+ * Handlers for built-in toolbar buttons.
112
+ * When a built-in button (e.g. ASK_ROVO, REFRESH) is clicked, the corresponding
113
+ * handler is invoked by the editor plugin.
114
+ */
115
+ editorToolbarHandlers?: EditorToolbarHandlers;
58
116
  /**
59
117
  * Ordered array of keys specifying which toolbar items to show and in what order.
60
118
  * The "More Options" dropdown is appended automatically based on `moreItems`.
@@ -1,13 +1,26 @@
1
- import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey } from './types';
1
+ import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameters } from './types';
2
2
  /**
3
- * Generic utility to update parameters on a native embed extension node.
4
- * Preserves existing parameters and merges in the new ones.
3
+ * Reads a value from extension parameters.macroParams by key.
4
+ * Supports both wrapped ({ value }) and unwrapped values.
5
5
  */
6
- export declare function updateParameters(current: {
7
- attrs?: Record<string, unknown>;
8
- }, parameterUpdates: Record<string, unknown>): {
9
- attrs: Record<string, unknown>;
10
- };
6
+ export declare const getParameter: <TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, key: TKey) => NativeEmbedParameterValues[TKey];
7
+ /**
8
+ * Gets native-embed parameters as resolved values.
9
+ * When key is provided, returns that single resolved value.
10
+ * When key is omitted, returns all resolved parameter values.
11
+ */
12
+ export declare function getParameters(parameters: NativeEmbedParameters | undefined): NativeEmbedParameterValues;
13
+ export declare function getParameters<TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, key: TKey): NativeEmbedParameterValues[TKey];
14
+ /**
15
+ * Sets a single key in parameters.macroParams using wrapped { value } format.
16
+ * Returns a new parameters object.
17
+ */
18
+ export declare const setParameter: <TKey extends NativeEmbedParameterKey>(parameters: NativeEmbedParameters | undefined, update: Pick<NativeEmbedParameterValues, TKey>) => NativeEmbedParameters;
19
+ /**
20
+ * Sets multiple keys in parameters.macroParams using wrapped { value } format.
21
+ * Returns a new parameters object.
22
+ */
23
+ export declare const setParameters: (parameters: NativeEmbedParameters | undefined, updates: Partial<NativeEmbedParameterValues>) => NativeEmbedParameters;
11
24
  /**
12
25
  * Helper function to create a type-safe ManifestEditorToolbarActions config.
13
26
  * Automatically infers custom action keys from the customActions object.
@@ -21,10 +34,16 @@ export declare function updateParameters(current: {
21
34
  * items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
22
35
  * moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
23
36
  * });
37
+ *
38
+ * // Or without custom actions:
39
+ * const simpleConfig = createEditorToolbarActions({
40
+ * items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
41
+ * moreItems: ['delete'],
42
+ * });
24
43
  * ```
25
44
  */
26
- export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction>>(config: {
27
- customActions: TCustomActions;
45
+ export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>>(config: {
46
+ customActions?: TCustomActions;
28
47
  items: (BuiltinToolbarKey | keyof TCustomActions)[];
29
48
  moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
30
49
  }) => ManifestEditorToolbarActions<TCustomActions>;
package/package.json CHANGED
@@ -24,9 +24,11 @@
24
24
  ],
25
25
  "atlaskit:src": "src/index.ts",
26
26
  "dependencies": {
27
- "@atlaskit/icon": "^32.0.0",
27
+ "@atlaskit/editor-common": "^112.4.0",
28
+ "@atlaskit/editor-prosemirror": "^7.3.0",
29
+ "@atlaskit/icon": "^33.0.0",
28
30
  "@babel/runtime": "^7.0.0",
29
- "@compiled/react": "^0.18.6"
31
+ "@compiled/react": "^0.20.0"
30
32
  },
31
33
  "peerDependencies": {
32
34
  "react": "^18.2.0"
@@ -77,7 +79,7 @@
77
79
  }
78
80
  },
79
81
  "name": "@atlaskit/native-embeds-common",
80
- "version": "0.1.0",
82
+ "version": "0.1.2",
81
83
  "description": "A shared package for native embeds to be used across experiences and plugin",
82
84
  "author": "Atlassian Pty Ltd",
83
85
  "license": "Apache-2.0",