@automattic/jetpack-ai-client 0.27.0 → 0.27.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 +17 -4
- package/build/hooks/use-post-content.d.ts +2 -1
- package/build/hooks/use-post-content.js +16 -3
- package/build/libs/get-all-blocks.d.ts +9 -0
- package/build/libs/get-all-blocks.js +20 -0
- package/build/libs/index.d.ts +1 -0
- package/build/libs/index.js +1 -0
- package/package.json +4 -4
- package/src/hooks/use-post-content.ts +24 -3
- package/src/libs/get-all-blocks.ts +29 -0
- package/src/libs/index.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.27.2] - 2025-03-12
|
|
9
|
+
### Changed
|
|
10
|
+
- Update dependencies. [#42328]
|
|
11
|
+
|
|
12
|
+
## [0.27.1] - 2025-03-10
|
|
13
|
+
### Added
|
|
14
|
+
- Add optional preprocess function to getPostContent. [#42269]
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Update dependencies. [#42222]
|
|
18
|
+
|
|
8
19
|
## [0.27.0] - 2025-03-03
|
|
9
20
|
### Added
|
|
10
|
-
-
|
|
21
|
+
- Move openBlockSidebar utility function. [#42016]
|
|
11
22
|
|
|
12
23
|
### Changed
|
|
13
24
|
- AI Assistant: Add experimental functionality to test Chrome's built-in AI API with the AI excerpt. [#41922]
|
|
14
|
-
-
|
|
15
|
-
-
|
|
25
|
+
- Move showAiAssistantSection function to AI Client. [#42158]
|
|
26
|
+
- Refactor usePostContent hook to expose isEditedPostEmpty. [#42149]
|
|
16
27
|
- Update package dependencies. [#42163]
|
|
17
28
|
|
|
18
29
|
## [0.26.3] - 2025-02-24
|
|
@@ -32,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
32
43
|
|
|
33
44
|
## [0.26.0] - 2025-02-10
|
|
34
45
|
### Added
|
|
35
|
-
- Add shared components from ai-assistant-plugin [#41078]
|
|
46
|
+
- Add shared components from ai-assistant-plugin. [#41078]
|
|
36
47
|
|
|
37
48
|
### Changed
|
|
38
49
|
- Updated package dependencies. [#41491] [#41577]
|
|
@@ -542,6 +553,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
542
553
|
- AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
|
|
543
554
|
- Updated package dependencies. [#31468] [#31659] [#31785]
|
|
544
555
|
|
|
556
|
+
[0.27.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.1...v0.27.2
|
|
557
|
+
[0.27.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.27.0...v0.27.1
|
|
545
558
|
[0.27.0]: https://github.com/Automattic/jetpack-ai-client/compare/v0.26.3...v0.27.0
|
|
546
559
|
[0.26.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.26.2...v0.26.3
|
|
547
560
|
[0.26.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.26.1...v0.26.2
|
|
@@ -21,10 +21,23 @@ const usePostContent = () => {
|
|
|
21
21
|
isEditedPostEmpty: coreEditorSelect.isEditedPostEmpty,
|
|
22
22
|
};
|
|
23
23
|
}, []);
|
|
24
|
-
const
|
|
24
|
+
const getSerializedPostContent = useCallback(() => {
|
|
25
25
|
const blocks = getBlocks();
|
|
26
|
-
|
|
26
|
+
if (blocks.length === 0) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
return serialize(blocks);
|
|
27
30
|
}, [getBlocks]);
|
|
28
|
-
|
|
31
|
+
const getPostContent = useCallback((preprocess) => {
|
|
32
|
+
let serialized = getSerializedPostContent();
|
|
33
|
+
if (!serialized) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
if (preprocess && typeof preprocess === 'function') {
|
|
37
|
+
serialized = preprocess(serialized);
|
|
38
|
+
}
|
|
39
|
+
return serialized ? renderMarkdownFromHTML({ content: serialized }) : '';
|
|
40
|
+
}, [getBlocks]);
|
|
41
|
+
return { getPostContent, isEditedPostEmpty, getSerializedPostContent };
|
|
29
42
|
};
|
|
30
43
|
export default usePostContent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Block } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Recursively get all blocks from the post, including nested innerBlocks
|
|
7
|
+
* @return {Array} Array of all blocks in the post
|
|
8
|
+
*/
|
|
9
|
+
export declare const getAllBlocks: () => Array<Block>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { select } from '@wordpress/data';
|
|
5
|
+
/**
|
|
6
|
+
* Recursively get all blocks from the post, including nested innerBlocks
|
|
7
|
+
* @return {Array} Array of all blocks in the post
|
|
8
|
+
*/
|
|
9
|
+
export const getAllBlocks = () => {
|
|
10
|
+
const topLevelBlocks = select('core/block-editor').getBlocks();
|
|
11
|
+
const allBlocks = [];
|
|
12
|
+
const processBlock = (block) => {
|
|
13
|
+
allBlocks.push(block);
|
|
14
|
+
if (block.innerBlocks?.length) {
|
|
15
|
+
block.innerBlocks.forEach(processBlock);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
topLevelBlocks.forEach(processBlock);
|
|
19
|
+
return allBlocks;
|
|
20
|
+
};
|
package/build/libs/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export type { RenderHTMLRules } from './markdown/index.js';
|
|
|
3
3
|
export { mapActionToHumanText } from './map-action-to-human-text.js';
|
|
4
4
|
export { openBlockSidebar } from './open-block-sidebar.js';
|
|
5
5
|
export { showAiAssistantSection } from './show-ai-assistant-section.js';
|
|
6
|
+
export { getAllBlocks } from './get-all-blocks.js';
|
package/build/libs/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { MarkdownToHTML, HTMLToMarkdown, renderHTMLFromMarkdown, renderMarkdownF
|
|
|
2
2
|
export { mapActionToHumanText } from './map-action-to-human-text.js';
|
|
3
3
|
export { openBlockSidebar } from './open-block-sidebar.js';
|
|
4
4
|
export { showAiAssistantSection } from './show-ai-assistant-section.js';
|
|
5
|
+
export { getAllBlocks } from './get-all-blocks.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@automattic/jetpack-ai-client",
|
|
4
|
-
"version": "0.27.
|
|
4
|
+
"version": "0.27.2",
|
|
5
5
|
"description": "A JS client for consuming Jetpack AI services",
|
|
6
6
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"types": "./build/index.d.ts",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@automattic/jetpack-base-styles": "^0.6.44",
|
|
48
|
-
"@automattic/jetpack-components": "^0.68.
|
|
49
|
-
"@automattic/jetpack-connection": "^0.
|
|
50
|
-
"@automattic/jetpack-shared-extension-utils": "^0.
|
|
48
|
+
"@automattic/jetpack-components": "^0.68.2",
|
|
49
|
+
"@automattic/jetpack-connection": "^0.39.1",
|
|
50
|
+
"@automattic/jetpack-shared-extension-utils": "^0.18.0",
|
|
51
51
|
"@microsoft/fetch-event-source": "2.0.1",
|
|
52
52
|
"@types/jest": "29.5.14",
|
|
53
53
|
"@types/react": "18.3.18",
|
|
@@ -28,13 +28,34 @@ const usePostContent = () => {
|
|
|
28
28
|
};
|
|
29
29
|
}, [] );
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const getSerializedPostContent = useCallback( () => {
|
|
32
32
|
const blocks = getBlocks();
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
if ( blocks.length === 0 ) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return serialize( blocks );
|
|
35
39
|
}, [ getBlocks ] );
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
const getPostContent = useCallback(
|
|
42
|
+
( preprocess?: ( serialized: string ) => string ) => {
|
|
43
|
+
let serialized = getSerializedPostContent();
|
|
44
|
+
|
|
45
|
+
if ( ! serialized ) {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ( preprocess && typeof preprocess === 'function' ) {
|
|
50
|
+
serialized = preprocess( serialized );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return serialized ? renderMarkdownFromHTML( { content: serialized } ) : '';
|
|
54
|
+
},
|
|
55
|
+
[ getBlocks ]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return { getPostContent, isEditedPostEmpty, getSerializedPostContent };
|
|
38
59
|
};
|
|
39
60
|
|
|
40
61
|
export default usePostContent;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { select } from '@wordpress/data';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { Block } from '../types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Recursively get all blocks from the post, including nested innerBlocks
|
|
12
|
+
* @return {Array} Array of all blocks in the post
|
|
13
|
+
*/
|
|
14
|
+
export const getAllBlocks = (): Array< Block > => {
|
|
15
|
+
const topLevelBlocks = select( 'core/block-editor' ).getBlocks();
|
|
16
|
+
const allBlocks: Array< Block > = [];
|
|
17
|
+
|
|
18
|
+
const processBlock = ( block: Block ) => {
|
|
19
|
+
allBlocks.push( block );
|
|
20
|
+
|
|
21
|
+
if ( block.innerBlocks?.length ) {
|
|
22
|
+
block.innerBlocks.forEach( processBlock );
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
topLevelBlocks.forEach( processBlock );
|
|
27
|
+
|
|
28
|
+
return allBlocks;
|
|
29
|
+
};
|
package/src/libs/index.ts
CHANGED
|
@@ -13,3 +13,5 @@ export { mapActionToHumanText } from './map-action-to-human-text.js';
|
|
|
13
13
|
export { openBlockSidebar } from './open-block-sidebar.js';
|
|
14
14
|
|
|
15
15
|
export { showAiAssistantSection } from './show-ai-assistant-section.js';
|
|
16
|
+
|
|
17
|
+
export { getAllBlocks } from './get-all-blocks.js';
|