@atlaskit/native-embeds-common 0.0.0 → 0.1.1
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 +9 -1
- package/dist/cjs/index.js +50 -1
- package/dist/cjs/utils/constants.js +40 -0
- package/dist/cjs/utils/types.js +5 -0
- package/dist/cjs/utils/utils.js +162 -0
- package/dist/es2019/index.js +7 -1
- package/dist/es2019/utils/constants.js +34 -0
- package/dist/es2019/utils/types.js +1 -0
- package/dist/es2019/utils/utils.js +132 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/utils/constants.js +34 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm/utils/utils.js +153 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +27 -0
- package/dist/types/utils/types.d.ts +134 -0
- package/dist/types/utils/utils.d.ts +49 -0
- package/dist/types-ts4.5/index.d.ts +3 -2
- package/dist/types-ts4.5/utils/constants.d.ts +46 -0
- package/dist/types-ts4.5/utils/types.d.ts +135 -0
- package/dist/types-ts4.5/utils/utils.d.ts +49 -0
- package/package.json +4 -2
- package/dist/cjs/constants.js +0 -12
- package/dist/cjs/types.js +0 -1
- package/dist/es2019/constants.js +0 -6
- package/dist/es2019/types.js +0 -0
- package/dist/esm/constants.js +0 -6
- package/dist/esm/types.js +0 -0
- package/dist/types/constants.d.ts +0 -5
- package/dist/types/types.d.ts +0 -1
- package/dist/types-ts4.5/constants.d.ts +0 -11
- package/dist/types-ts4.5/types.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
# @atlaskit/native-embeds-common
|
|
1
|
+
# @atlaskit/native-embeds-common
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`71180287b9fed`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/71180287b9fed) -
|
|
8
|
+
pen inline prompt when ask rovo is clicked on a maui app and send the context to the api
|
|
9
|
+
- Updated dependencies
|
package/dist/cjs/index.js
CHANGED
|
@@ -9,10 +9,59 @@ Object.defineProperty(exports, "ALIGNMENT_VALUES", {
|
|
|
9
9
|
return _constants.ALIGNMENT_VALUES;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "BUILTIN_TOOLBAR_KEYS", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _constants.BUILTIN_TOOLBAR_KEYS;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "DEFAULT_ALIGNMENT", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function get() {
|
|
15
21
|
return _constants.DEFAULT_ALIGNMENT;
|
|
16
22
|
}
|
|
17
23
|
});
|
|
18
|
-
|
|
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
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "createEditorToolbarActions", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _utils.createEditorToolbarActions;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
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", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _utils.setParameters;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var _constants = require("./utils/constants");
|
|
67
|
+
var _utils = require("./utils/utils");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NATIVE_EMBED_PARAMETER_DEFAULTS = exports.EDITOR_TOOLBAR_HANDLER_KEYS = exports.DEFAULT_ALIGNMENT = exports.BUILTIN_TOOLBAR_KEYS = exports.ALIGNMENT_VALUES = void 0;
|
|
7
|
+
// Alignment constants
|
|
8
|
+
var ALIGNMENT_VALUES = exports.ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
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
|
+
height: 600,
|
|
15
|
+
width: undefined
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Built-in keys that can be referenced in the `items` and `moreItems` arrays.
|
|
20
|
+
*
|
|
21
|
+
* Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
|
|
22
|
+
* More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
|
|
23
|
+
* Shared: SEPARATOR (usable in both)
|
|
24
|
+
*/
|
|
25
|
+
var BUILTIN_TOOLBAR_KEYS = exports.BUILTIN_TOOLBAR_KEYS = {
|
|
26
|
+
ASK_ROVO: 'askRovo',
|
|
27
|
+
REFRESH: 'refresh',
|
|
28
|
+
EDIT: 'edit',
|
|
29
|
+
EMBED: 'embed',
|
|
30
|
+
BORDER: 'border',
|
|
31
|
+
ALIGNMENT: 'alignment',
|
|
32
|
+
OPEN_IN_NEW_WINDOW: 'openInNewWindow',
|
|
33
|
+
EDIT_URL: 'editUrl',
|
|
34
|
+
ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
|
|
35
|
+
SET_EMBED_TYPE: 'setEmbedType',
|
|
36
|
+
COPY_LINK: 'copyLink',
|
|
37
|
+
DELETE: 'delete',
|
|
38
|
+
SEPARATOR: 'separator'
|
|
39
|
+
};
|
|
40
|
+
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,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getParameter = exports.createEditorToolbarActions = void 0;
|
|
8
|
+
exports.getParameters = getParameters;
|
|
9
|
+
exports.setParameters = exports.setParameter = void 0;
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
+
var _constants = require("./constants");
|
|
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; }
|
|
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
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reads a value from extension parameters.macroParams by key.
|
|
75
|
+
* Supports both wrapped ({ value }) and unwrapped values.
|
|
76
|
+
*/
|
|
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
|
+
}));
|
|
100
|
+
}
|
|
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
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Helper function to create a type-safe ManifestEditorToolbarActions config.
|
|
141
|
+
* Automatically infers custom action keys from the customActions object.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const config = createEditorToolbarActions({
|
|
146
|
+
* customActions: {
|
|
147
|
+
* myAction: { type: 'button', key: 'myAction', ... },
|
|
148
|
+
* },
|
|
149
|
+
* items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
|
|
150
|
+
* moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Or without custom actions:
|
|
154
|
+
* const simpleConfig = createEditorToolbarActions({
|
|
155
|
+
* items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
|
|
156
|
+
* moreItems: ['delete'],
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
var createEditorToolbarActions = exports.createEditorToolbarActions = function createEditorToolbarActions(config) {
|
|
161
|
+
return config;
|
|
162
|
+
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
// Re-export constants
|
|
2
|
+
export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS } from './utils/constants';
|
|
3
|
+
|
|
4
|
+
// Re-export types
|
|
5
|
+
|
|
6
|
+
// Re-export utilities
|
|
7
|
+
export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters } from './utils/utils';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Alignment constants
|
|
2
|
+
export const ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
3
|
+
export const DEFAULT_ALIGNMENT = 'center';
|
|
4
|
+
export const NATIVE_EMBED_PARAMETER_DEFAULTS = {
|
|
5
|
+
url: undefined,
|
|
6
|
+
alwaysShowTitle: false,
|
|
7
|
+
alignment: DEFAULT_ALIGNMENT,
|
|
8
|
+
height: 600,
|
|
9
|
+
width: undefined
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Built-in keys that can be referenced in the `items` and `moreItems` arrays.
|
|
14
|
+
*
|
|
15
|
+
* Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
|
|
16
|
+
* More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
|
|
17
|
+
* Shared: SEPARATOR (usable in both)
|
|
18
|
+
*/
|
|
19
|
+
export const BUILTIN_TOOLBAR_KEYS = {
|
|
20
|
+
ASK_ROVO: 'askRovo',
|
|
21
|
+
REFRESH: 'refresh',
|
|
22
|
+
EDIT: 'edit',
|
|
23
|
+
EMBED: 'embed',
|
|
24
|
+
BORDER: 'border',
|
|
25
|
+
ALIGNMENT: 'alignment',
|
|
26
|
+
OPEN_IN_NEW_WINDOW: 'openInNewWindow',
|
|
27
|
+
EDIT_URL: 'editUrl',
|
|
28
|
+
ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
|
|
29
|
+
SET_EMBED_TYPE: 'setEmbedType',
|
|
30
|
+
COPY_LINK: 'copyLink',
|
|
31
|
+
DELETE: 'delete',
|
|
32
|
+
SEPARATOR: 'separator'
|
|
33
|
+
};
|
|
34
|
+
export const EDITOR_TOOLBAR_HANDLER_KEYS = ['onAlignmentClick', 'onAppearanceClick', 'onAskRovoClick', 'onCopyLinkClick', 'onChangeBorderClick', 'onDeleteClick', 'onEditUrlClick', 'onEditClick', 'onOpenInNewWindowClick', 'onRefreshClick', 'onSetEmbedTypeClick', 'onShowTitleClick'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads a value from extension parameters.macroParams by key.
|
|
59
|
+
* Supports both wrapped ({ value }) and unwrapped values.
|
|
60
|
+
*/
|
|
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
|
+
}]));
|
|
102
|
+
return {
|
|
103
|
+
...currentParameters,
|
|
104
|
+
macroParams: {
|
|
105
|
+
...currentMacroParams,
|
|
106
|
+
...wrappedUpdates
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Helper function to create a type-safe ManifestEditorToolbarActions config.
|
|
113
|
+
* Automatically infers custom action keys from the customActions object.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const config = createEditorToolbarActions({
|
|
118
|
+
* customActions: {
|
|
119
|
+
* myAction: { type: 'button', key: 'myAction', ... },
|
|
120
|
+
* },
|
|
121
|
+
* items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
|
|
122
|
+
* moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* // Or without custom actions:
|
|
126
|
+
* const simpleConfig = createEditorToolbarActions({
|
|
127
|
+
* items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
|
|
128
|
+
* moreItems: ['delete'],
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export const createEditorToolbarActions = config => config;
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
// Re-export constants
|
|
2
|
+
export { ALIGNMENT_VALUES, DEFAULT_ALIGNMENT, BUILTIN_TOOLBAR_KEYS, EDITOR_TOOLBAR_HANDLER_KEYS, NATIVE_EMBED_PARAMETER_DEFAULTS } from './utils/constants';
|
|
3
|
+
|
|
4
|
+
// Re-export types
|
|
5
|
+
|
|
6
|
+
// Re-export utilities
|
|
7
|
+
export { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters } from './utils/utils';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Alignment constants
|
|
2
|
+
export var ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
3
|
+
export var DEFAULT_ALIGNMENT = 'center';
|
|
4
|
+
export var NATIVE_EMBED_PARAMETER_DEFAULTS = {
|
|
5
|
+
url: undefined,
|
|
6
|
+
alwaysShowTitle: false,
|
|
7
|
+
alignment: DEFAULT_ALIGNMENT,
|
|
8
|
+
height: 600,
|
|
9
|
+
width: undefined
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Built-in keys that can be referenced in the `items` and `moreItems` arrays.
|
|
14
|
+
*
|
|
15
|
+
* Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
|
|
16
|
+
* More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
|
|
17
|
+
* Shared: SEPARATOR (usable in both)
|
|
18
|
+
*/
|
|
19
|
+
export var BUILTIN_TOOLBAR_KEYS = {
|
|
20
|
+
ASK_ROVO: 'askRovo',
|
|
21
|
+
REFRESH: 'refresh',
|
|
22
|
+
EDIT: 'edit',
|
|
23
|
+
EMBED: 'embed',
|
|
24
|
+
BORDER: 'border',
|
|
25
|
+
ALIGNMENT: 'alignment',
|
|
26
|
+
OPEN_IN_NEW_WINDOW: 'openInNewWindow',
|
|
27
|
+
EDIT_URL: 'editUrl',
|
|
28
|
+
ALWAYS_SHOW_TITLE: 'alwaysShowTitle',
|
|
29
|
+
SET_EMBED_TYPE: 'setEmbedType',
|
|
30
|
+
COPY_LINK: 'copyLink',
|
|
31
|
+
DELETE: 'delete',
|
|
32
|
+
SEPARATOR: 'separator'
|
|
33
|
+
};
|
|
34
|
+
export var EDITOR_TOOLBAR_HANDLER_KEYS = ['onAlignmentClick', 'onAppearanceClick', 'onAskRovoClick', 'onCopyLinkClick', 'onChangeBorderClick', 'onDeleteClick', 'onEditUrlClick', 'onEditClick', 'onOpenInNewWindowClick', 'onRefreshClick', 'onSetEmbedTypeClick', 'onShowTitleClick'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
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; }
|
|
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
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reads a value from extension parameters.macroParams by key.
|
|
66
|
+
* Supports both wrapped ({ value }) and unwrapped values.
|
|
67
|
+
*/
|
|
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
|
+
}));
|
|
91
|
+
}
|
|
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
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Helper function to create a type-safe ManifestEditorToolbarActions config.
|
|
132
|
+
* Automatically infers custom action keys from the customActions object.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const config = createEditorToolbarActions({
|
|
137
|
+
* customActions: {
|
|
138
|
+
* myAction: { type: 'button', key: 'myAction', ... },
|
|
139
|
+
* },
|
|
140
|
+
* items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
|
|
141
|
+
* moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Or without custom actions:
|
|
145
|
+
* const simpleConfig = createEditorToolbarActions({
|
|
146
|
+
* items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
|
|
147
|
+
* moreItems: ['delete'],
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export var createEditorToolbarActions = function createEditorToolbarActions(config) {
|
|
152
|
+
return config;
|
|
153
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
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 { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters, } from './utils/utils';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NativeEmbedParameterValues } from './types';
|
|
2
|
+
export declare const ALIGNMENT_VALUES: readonly ["left", "center", "right", "wrap-left", "wrap-right"];
|
|
3
|
+
export declare const DEFAULT_ALIGNMENT: "center";
|
|
4
|
+
export declare const NATIVE_EMBED_PARAMETER_DEFAULTS: NativeEmbedParameterValues;
|
|
5
|
+
/**
|
|
6
|
+
* Built-in keys that can be referenced in the `items` and `moreItems` arrays.
|
|
7
|
+
*
|
|
8
|
+
* Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
|
|
9
|
+
* More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
|
|
10
|
+
* Shared: SEPARATOR (usable in both)
|
|
11
|
+
*/
|
|
12
|
+
export declare const BUILTIN_TOOLBAR_KEYS: {
|
|
13
|
+
readonly ASK_ROVO: "askRovo";
|
|
14
|
+
readonly REFRESH: "refresh";
|
|
15
|
+
readonly EDIT: "edit";
|
|
16
|
+
readonly EMBED: "embed";
|
|
17
|
+
readonly BORDER: "border";
|
|
18
|
+
readonly ALIGNMENT: "alignment";
|
|
19
|
+
readonly OPEN_IN_NEW_WINDOW: "openInNewWindow";
|
|
20
|
+
readonly EDIT_URL: "editUrl";
|
|
21
|
+
readonly ALWAYS_SHOW_TITLE: "alwaysShowTitle";
|
|
22
|
+
readonly SET_EMBED_TYPE: "setEmbedType";
|
|
23
|
+
readonly COPY_LINK: "copyLink";
|
|
24
|
+
readonly DELETE: "delete";
|
|
25
|
+
readonly SEPARATOR: "separator";
|
|
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,134 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { NewCoreIconProps } from '@atlaskit/icon';
|
|
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
|
+
height: number;
|
|
11
|
+
url?: string;
|
|
12
|
+
width?: number;
|
|
13
|
+
};
|
|
14
|
+
export type NativeEmbedParameterValue = {
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
export type NativeEmbedParameters = {
|
|
18
|
+
macroParams?: {
|
|
19
|
+
alignment?: NativeEmbedParameterValue;
|
|
20
|
+
alwaysShowTitle?: NativeEmbedParameterValue;
|
|
21
|
+
height?: NativeEmbedParameterValue;
|
|
22
|
+
url?: NativeEmbedParameterValue;
|
|
23
|
+
width?: NativeEmbedParameterValue;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type NativeEmbedParameterKey = keyof NonNullable<NativeEmbedParameters['macroParams']>;
|
|
27
|
+
export type EditorToolbarHandlerContext = {
|
|
28
|
+
editorApi?: PublicPluginAPI<[]>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A button action rendered in the editor floating toolbar.
|
|
32
|
+
*/
|
|
33
|
+
export type EditorToolbarButtonAction = {
|
|
34
|
+
/**
|
|
35
|
+
* Whether this action is disabled.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Handler key that maps to the actionHandlers config in the editor plugin.
|
|
41
|
+
* When clicked, the plugin looks up actionHandlers[handlerKey] and invokes it.
|
|
42
|
+
*/
|
|
43
|
+
handlerKey: string;
|
|
44
|
+
/**
|
|
45
|
+
* Icon component to display.
|
|
46
|
+
*/
|
|
47
|
+
icon: ComponentType<NewCoreIconProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Unique key for this action, used for React keys and test IDs.
|
|
50
|
+
*/
|
|
51
|
+
key: string;
|
|
52
|
+
/**
|
|
53
|
+
* Button label (used for tooltip and accessibility).
|
|
54
|
+
*/
|
|
55
|
+
label: string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether to show the label as text next to the icon.
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
showTitle?: boolean;
|
|
61
|
+
type: 'button';
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Union type for editor toolbar actions.
|
|
65
|
+
* Currently only supports buttons; dropdowns and separators can be added later.
|
|
66
|
+
*/
|
|
67
|
+
export type EditorToolbarAction = EditorToolbarButtonAction;
|
|
68
|
+
/**
|
|
69
|
+
* Handlers for built-in native embed floating toolbar actions.
|
|
70
|
+
* Can be defined in the manifest (editorToolbarHandlers) and are invoked
|
|
71
|
+
* by the editor plugin when the corresponding toolbar buttons are clicked.
|
|
72
|
+
* Handlers with context (e.g. onAlignmentClick, onAppearanceClick) receive
|
|
73
|
+
* an optional second parameter for the action-specific value.
|
|
74
|
+
*/
|
|
75
|
+
export type EditorToolbarHandlerKey = (typeof EDITOR_TOOLBAR_HANDLER_KEYS)[number];
|
|
76
|
+
export type EditorToolbarHandlers = Partial<{
|
|
77
|
+
onAlignmentClick: (parameters: NativeEmbedParameterValues, alignment: AlignmentValue, context?: EditorToolbarHandlerContext) => void;
|
|
78
|
+
onAppearanceClick: (parameters: NativeEmbedParameterValues, appearance: NativeEmbedAppearance, context?: EditorToolbarHandlerContext) => void;
|
|
79
|
+
onAskRovoClick: (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
|
|
80
|
+
onChangeBorderClick: EditorToolbarHandler;
|
|
81
|
+
onCopyLinkClick: EditorToolbarHandler;
|
|
82
|
+
onDeleteClick: EditorToolbarHandler;
|
|
83
|
+
onEditClick: EditorToolbarHandler;
|
|
84
|
+
onEditUrlClick: EditorToolbarHandler;
|
|
85
|
+
onOpenInNewWindowClick: EditorToolbarHandler;
|
|
86
|
+
onRefreshClick: EditorToolbarHandler;
|
|
87
|
+
onSetEmbedTypeClick: EditorToolbarHandler;
|
|
88
|
+
onShowTitleClick: EditorToolbarHandler;
|
|
89
|
+
}>;
|
|
90
|
+
/** Base handler signature for contexts that don't have action-specific context. */
|
|
91
|
+
export type EditorToolbarHandler = (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
|
|
92
|
+
export type BuiltinToolbarKey = (typeof BUILTIN_TOOLBAR_KEYS)[keyof typeof BUILTIN_TOOLBAR_KEYS];
|
|
93
|
+
/**
|
|
94
|
+
* Configuration for editor toolbar actions in the manifest.
|
|
95
|
+
*
|
|
96
|
+
* Use `customActions` map + `items` array to mix custom and built-in actions.
|
|
97
|
+
*
|
|
98
|
+
* @typeParam TCustomActions - The type of the customActions record. Keys are automatically
|
|
99
|
+
* inferred and used to type-check the `items` array.
|
|
100
|
+
*/
|
|
101
|
+
export type ManifestEditorToolbarActions<TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>> = {
|
|
102
|
+
/**
|
|
103
|
+
* Custom action definitions, keyed by unique identifier.
|
|
104
|
+
* These can be referenced in the `items` array alongside built-in keys.
|
|
105
|
+
*/
|
|
106
|
+
customActions?: TCustomActions;
|
|
107
|
+
/**
|
|
108
|
+
* Handlers for built-in toolbar buttons.
|
|
109
|
+
* When a built-in button (e.g. ASK_ROVO, REFRESH) is clicked, the corresponding
|
|
110
|
+
* handler is invoked by the editor plugin.
|
|
111
|
+
*/
|
|
112
|
+
editorToolbarHandlers?: EditorToolbarHandlers;
|
|
113
|
+
/**
|
|
114
|
+
* Ordered array of keys specifying which toolbar items to show and in what order.
|
|
115
|
+
* The "More Options" dropdown is appended automatically based on `moreItems`.
|
|
116
|
+
*
|
|
117
|
+
* Can include:
|
|
118
|
+
* - Built-in keys: 'refresh', 'embed', 'border', 'alignment', 'openInNewWindow'
|
|
119
|
+
* - 'separator' for visual separators between groups
|
|
120
|
+
* - Custom keys defined in `customActions`
|
|
121
|
+
*/
|
|
122
|
+
items?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
123
|
+
/**
|
|
124
|
+
* Ordered array of keys specifying which items appear in the "More Options" dropdown.
|
|
125
|
+
* When provided with at least one item, a separator and the dropdown are automatically
|
|
126
|
+
* appended to the toolbar. When omitted, the default set of dropdown items is used.
|
|
127
|
+
*
|
|
128
|
+
* Can include:
|
|
129
|
+
* - Built-in keys: 'alwaysShowTitle', 'setEmbedType', 'copyLink', 'delete'
|
|
130
|
+
* - 'separator' for visual separators between groups
|
|
131
|
+
* - Custom keys defined in `customActions` (shared with the toolbar)
|
|
132
|
+
*/
|
|
133
|
+
moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
134
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameters } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a value from extension parameters.macroParams by key.
|
|
4
|
+
* Supports both wrapped ({ value }) and unwrapped values.
|
|
5
|
+
*/
|
|
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;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to create a type-safe ManifestEditorToolbarActions config.
|
|
26
|
+
* Automatically infers custom action keys from the customActions object.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const config = createEditorToolbarActions({
|
|
31
|
+
* customActions: {
|
|
32
|
+
* myAction: { type: 'button', key: 'myAction', ... },
|
|
33
|
+
* },
|
|
34
|
+
* items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
|
|
35
|
+
* moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Or without custom actions:
|
|
39
|
+
* const simpleConfig = createEditorToolbarActions({
|
|
40
|
+
* items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
|
|
41
|
+
* moreItems: ['delete'],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>>(config: {
|
|
46
|
+
customActions?: TCustomActions;
|
|
47
|
+
items: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
48
|
+
moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
49
|
+
}) => ManifestEditorToolbarActions<TCustomActions>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
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 { createEditorToolbarActions, getParameter, getParameters, setParameter, setParameters, } from './utils/utils';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { NativeEmbedParameterValues } from './types';
|
|
2
|
+
export declare const ALIGNMENT_VALUES: readonly [
|
|
3
|
+
"left",
|
|
4
|
+
"center",
|
|
5
|
+
"right",
|
|
6
|
+
"wrap-left",
|
|
7
|
+
"wrap-right"
|
|
8
|
+
];
|
|
9
|
+
export declare const DEFAULT_ALIGNMENT: "center";
|
|
10
|
+
export declare const NATIVE_EMBED_PARAMETER_DEFAULTS: NativeEmbedParameterValues;
|
|
11
|
+
/**
|
|
12
|
+
* Built-in keys that can be referenced in the `items` and `moreItems` arrays.
|
|
13
|
+
*
|
|
14
|
+
* Toolbar keys: ASK_ROVO, REFRESH, EDIT, EMBED, BORDER, ALIGNMENT, OPEN_IN_NEW_WINDOW
|
|
15
|
+
* More Options dropdown keys: ALWAYS_SHOW_TITLE, SET_EMBED_TYPE, COPY_LINK, DELETE
|
|
16
|
+
* Shared: SEPARATOR (usable in both)
|
|
17
|
+
*/
|
|
18
|
+
export declare const BUILTIN_TOOLBAR_KEYS: {
|
|
19
|
+
readonly ASK_ROVO: "askRovo";
|
|
20
|
+
readonly REFRESH: "refresh";
|
|
21
|
+
readonly EDIT: "edit";
|
|
22
|
+
readonly EMBED: "embed";
|
|
23
|
+
readonly BORDER: "border";
|
|
24
|
+
readonly ALIGNMENT: "alignment";
|
|
25
|
+
readonly OPEN_IN_NEW_WINDOW: "openInNewWindow";
|
|
26
|
+
readonly EDIT_URL: "editUrl";
|
|
27
|
+
readonly ALWAYS_SHOW_TITLE: "alwaysShowTitle";
|
|
28
|
+
readonly SET_EMBED_TYPE: "setEmbedType";
|
|
29
|
+
readonly COPY_LINK: "copyLink";
|
|
30
|
+
readonly DELETE: "delete";
|
|
31
|
+
readonly SEPARATOR: "separator";
|
|
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,135 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { NewCoreIconProps } from '@atlaskit/icon';
|
|
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
|
+
height: number;
|
|
11
|
+
url?: string;
|
|
12
|
+
width?: number;
|
|
13
|
+
};
|
|
14
|
+
export type NativeEmbedParameterValue = {
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
export type NativeEmbedParameters = {
|
|
18
|
+
macroParams?: {
|
|
19
|
+
alignment?: NativeEmbedParameterValue;
|
|
20
|
+
alwaysShowTitle?: NativeEmbedParameterValue;
|
|
21
|
+
height?: NativeEmbedParameterValue;
|
|
22
|
+
url?: NativeEmbedParameterValue;
|
|
23
|
+
width?: NativeEmbedParameterValue;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type NativeEmbedParameterKey = keyof NonNullable<NativeEmbedParameters['macroParams']>;
|
|
27
|
+
export type EditorToolbarHandlerContext = {
|
|
28
|
+
editorApi?: PublicPluginAPI<[
|
|
29
|
+
]>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A button action rendered in the editor floating toolbar.
|
|
33
|
+
*/
|
|
34
|
+
export type EditorToolbarButtonAction = {
|
|
35
|
+
/**
|
|
36
|
+
* Whether this action is disabled.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Handler key that maps to the actionHandlers config in the editor plugin.
|
|
42
|
+
* When clicked, the plugin looks up actionHandlers[handlerKey] and invokes it.
|
|
43
|
+
*/
|
|
44
|
+
handlerKey: string;
|
|
45
|
+
/**
|
|
46
|
+
* Icon component to display.
|
|
47
|
+
*/
|
|
48
|
+
icon: ComponentType<NewCoreIconProps>;
|
|
49
|
+
/**
|
|
50
|
+
* Unique key for this action, used for React keys and test IDs.
|
|
51
|
+
*/
|
|
52
|
+
key: string;
|
|
53
|
+
/**
|
|
54
|
+
* Button label (used for tooltip and accessibility).
|
|
55
|
+
*/
|
|
56
|
+
label: string;
|
|
57
|
+
/**
|
|
58
|
+
* Whether to show the label as text next to the icon.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
showTitle?: boolean;
|
|
62
|
+
type: 'button';
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Union type for editor toolbar actions.
|
|
66
|
+
* Currently only supports buttons; dropdowns and separators can be added later.
|
|
67
|
+
*/
|
|
68
|
+
export type EditorToolbarAction = EditorToolbarButtonAction;
|
|
69
|
+
/**
|
|
70
|
+
* Handlers for built-in native embed floating toolbar actions.
|
|
71
|
+
* Can be defined in the manifest (editorToolbarHandlers) and are invoked
|
|
72
|
+
* by the editor plugin when the corresponding toolbar buttons are clicked.
|
|
73
|
+
* Handlers with context (e.g. onAlignmentClick, onAppearanceClick) receive
|
|
74
|
+
* an optional second parameter for the action-specific value.
|
|
75
|
+
*/
|
|
76
|
+
export type EditorToolbarHandlerKey = (typeof EDITOR_TOOLBAR_HANDLER_KEYS)[number];
|
|
77
|
+
export type EditorToolbarHandlers = Partial<{
|
|
78
|
+
onAlignmentClick: (parameters: NativeEmbedParameterValues, alignment: AlignmentValue, context?: EditorToolbarHandlerContext) => void;
|
|
79
|
+
onAppearanceClick: (parameters: NativeEmbedParameterValues, appearance: NativeEmbedAppearance, context?: EditorToolbarHandlerContext) => void;
|
|
80
|
+
onAskRovoClick: (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
|
|
81
|
+
onChangeBorderClick: EditorToolbarHandler;
|
|
82
|
+
onCopyLinkClick: EditorToolbarHandler;
|
|
83
|
+
onDeleteClick: EditorToolbarHandler;
|
|
84
|
+
onEditClick: EditorToolbarHandler;
|
|
85
|
+
onEditUrlClick: EditorToolbarHandler;
|
|
86
|
+
onOpenInNewWindowClick: EditorToolbarHandler;
|
|
87
|
+
onRefreshClick: EditorToolbarHandler;
|
|
88
|
+
onSetEmbedTypeClick: EditorToolbarHandler;
|
|
89
|
+
onShowTitleClick: EditorToolbarHandler;
|
|
90
|
+
}>;
|
|
91
|
+
/** Base handler signature for contexts that don't have action-specific context. */
|
|
92
|
+
export type EditorToolbarHandler = (parameters: NativeEmbedParameterValues, context?: EditorToolbarHandlerContext) => void;
|
|
93
|
+
export type BuiltinToolbarKey = (typeof BUILTIN_TOOLBAR_KEYS)[keyof typeof BUILTIN_TOOLBAR_KEYS];
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for editor toolbar actions in the manifest.
|
|
96
|
+
*
|
|
97
|
+
* Use `customActions` map + `items` array to mix custom and built-in actions.
|
|
98
|
+
*
|
|
99
|
+
* @typeParam TCustomActions - The type of the customActions record. Keys are automatically
|
|
100
|
+
* inferred and used to type-check the `items` array.
|
|
101
|
+
*/
|
|
102
|
+
export type ManifestEditorToolbarActions<TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>> = {
|
|
103
|
+
/**
|
|
104
|
+
* Custom action definitions, keyed by unique identifier.
|
|
105
|
+
* These can be referenced in the `items` array alongside built-in keys.
|
|
106
|
+
*/
|
|
107
|
+
customActions?: TCustomActions;
|
|
108
|
+
/**
|
|
109
|
+
* Handlers for built-in toolbar buttons.
|
|
110
|
+
* When a built-in button (e.g. ASK_ROVO, REFRESH) is clicked, the corresponding
|
|
111
|
+
* handler is invoked by the editor plugin.
|
|
112
|
+
*/
|
|
113
|
+
editorToolbarHandlers?: EditorToolbarHandlers;
|
|
114
|
+
/**
|
|
115
|
+
* Ordered array of keys specifying which toolbar items to show and in what order.
|
|
116
|
+
* The "More Options" dropdown is appended automatically based on `moreItems`.
|
|
117
|
+
*
|
|
118
|
+
* Can include:
|
|
119
|
+
* - Built-in keys: 'refresh', 'embed', 'border', 'alignment', 'openInNewWindow'
|
|
120
|
+
* - 'separator' for visual separators between groups
|
|
121
|
+
* - Custom keys defined in `customActions`
|
|
122
|
+
*/
|
|
123
|
+
items?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
124
|
+
/**
|
|
125
|
+
* Ordered array of keys specifying which items appear in the "More Options" dropdown.
|
|
126
|
+
* When provided with at least one item, a separator and the dropdown are automatically
|
|
127
|
+
* appended to the toolbar. When omitted, the default set of dropdown items is used.
|
|
128
|
+
*
|
|
129
|
+
* Can include:
|
|
130
|
+
* - Built-in keys: 'alwaysShowTitle', 'setEmbedType', 'copyLink', 'delete'
|
|
131
|
+
* - 'separator' for visual separators between groups
|
|
132
|
+
* - Custom keys defined in `customActions` (shared with the toolbar)
|
|
133
|
+
*/
|
|
134
|
+
moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
135
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ManifestEditorToolbarActions, EditorToolbarAction, BuiltinToolbarKey, NativeEmbedParameterKey, NativeEmbedParameterValues, NativeEmbedParameters } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a value from extension parameters.macroParams by key.
|
|
4
|
+
* Supports both wrapped ({ value }) and unwrapped values.
|
|
5
|
+
*/
|
|
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;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to create a type-safe ManifestEditorToolbarActions config.
|
|
26
|
+
* Automatically infers custom action keys from the customActions object.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const config = createEditorToolbarActions({
|
|
31
|
+
* customActions: {
|
|
32
|
+
* myAction: { type: 'button', key: 'myAction', ... },
|
|
33
|
+
* },
|
|
34
|
+
* items: ['refresh', 'myAction', 'separator'], // 'myAction' is type-checked
|
|
35
|
+
* moreItems: ['copyLink', 'myAction', 'separator', 'delete'], // 'myAction' is type-checked
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Or without custom actions:
|
|
39
|
+
* const simpleConfig = createEditorToolbarActions({
|
|
40
|
+
* items: ['alignment', 'separator', 'openInNewWindow', 'editUrl'],
|
|
41
|
+
* moreItems: ['delete'],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const createEditorToolbarActions: <const TCustomActions extends Record<string, EditorToolbarAction> = Record<string, EditorToolbarAction>>(config: {
|
|
46
|
+
customActions?: TCustomActions;
|
|
47
|
+
items: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
48
|
+
moreItems?: (BuiltinToolbarKey | keyof TCustomActions)[];
|
|
49
|
+
}) => ManifestEditorToolbarActions<TCustomActions>;
|
package/package.json
CHANGED
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
],
|
|
25
25
|
"atlaskit:src": "src/index.ts",
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@atlaskit/editor-common": "^112.0.0",
|
|
28
|
+
"@atlaskit/icon": "^32.0.0",
|
|
27
29
|
"@babel/runtime": "^7.0.0",
|
|
28
|
-
"@compiled/react": "^0.
|
|
30
|
+
"@compiled/react": "^0.20.0"
|
|
29
31
|
},
|
|
30
32
|
"peerDependencies": {
|
|
31
33
|
"react": "^18.2.0"
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
}
|
|
77
79
|
},
|
|
78
80
|
"name": "@atlaskit/native-embeds-common",
|
|
79
|
-
"version": "0.
|
|
81
|
+
"version": "0.1.1",
|
|
80
82
|
"description": "A shared package for native embeds to be used across experiences and plugin",
|
|
81
83
|
"author": "Atlassian Pty Ltd",
|
|
82
84
|
"license": "Apache-2.0",
|
package/dist/cjs/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DEFAULT_ALIGNMENT = exports.ALIGNMENT_VALUES = void 0;
|
|
7
|
-
var ALIGNMENT_VALUES = exports.ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
8
|
-
|
|
9
|
-
/** Alignment value for native embed extension parameters. Single source of truth. */
|
|
10
|
-
|
|
11
|
-
/** Default alignment when not set in parameters. */
|
|
12
|
-
var DEFAULT_ALIGNMENT = exports.DEFAULT_ALIGNMENT = 'center';
|
package/dist/cjs/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/es2019/constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
2
|
-
|
|
3
|
-
/** Alignment value for native embed extension parameters. Single source of truth. */
|
|
4
|
-
|
|
5
|
-
/** Default alignment when not set in parameters. */
|
|
6
|
-
export const DEFAULT_ALIGNMENT = 'center';
|
package/dist/es2019/types.js
DELETED
|
File without changes
|
package/dist/esm/constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var ALIGNMENT_VALUES = ['left', 'center', 'right', 'wrap-left', 'wrap-right'];
|
|
2
|
-
|
|
3
|
-
/** Alignment value for native embed extension parameters. Single source of truth. */
|
|
4
|
-
|
|
5
|
-
/** Default alignment when not set in parameters. */
|
|
6
|
-
export var DEFAULT_ALIGNMENT = 'center';
|
package/dist/esm/types.js
DELETED
|
File without changes
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const ALIGNMENT_VALUES: readonly ["left", "center", "right", "wrap-left", "wrap-right"];
|
|
2
|
-
/** Alignment value for native embed extension parameters. Single source of truth. */
|
|
3
|
-
export type AlignmentValue = (typeof ALIGNMENT_VALUES)[number];
|
|
4
|
-
/** Default alignment when not set in parameters. */
|
|
5
|
-
export declare const DEFAULT_ALIGNMENT: AlignmentValue;
|
package/dist/types/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { AlignmentValue } from './constants';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const ALIGNMENT_VALUES: readonly [
|
|
2
|
-
"left",
|
|
3
|
-
"center",
|
|
4
|
-
"right",
|
|
5
|
-
"wrap-left",
|
|
6
|
-
"wrap-right"
|
|
7
|
-
];
|
|
8
|
-
/** Alignment value for native embed extension parameters. Single source of truth. */
|
|
9
|
-
export type AlignmentValue = (typeof ALIGNMENT_VALUES)[number];
|
|
10
|
-
/** Default alignment when not set in parameters. */
|
|
11
|
-
export declare const DEFAULT_ALIGNMENT: AlignmentValue;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { AlignmentValue } from './constants';
|