Skip to content

Commit 93aa561

Browse files
Merge branch 'develop'
2 parents af4d910 + 841d939 commit 93aa561

File tree

14 files changed

+283
-35
lines changed

14 files changed

+283
-35
lines changed

assets/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/build/store.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The documentation plugin for WordPress. Create great looking documentation for your products.
44

5+
[Preview in WordPress Playground](https://playground.wordpress.net/?plugin=wedocs&blueprint-url=https%3A%2F%2Fwordpress.org%2Fplugins%2Fwp-json%2Fplugins%2Fv1%2Fplugin%2Fwedocs%2Fblueprint.json%3Frev%3D3372138%26lang%3Den_US)
6+
57
![WordPress Plugin Version](https://img.shields.io/badge/PLUGIN_VERSION-V2.1.7-blue) ![WordPress Plugin Active Installs](https://img.shields.io/badge/ACTIVE_INSTALLS-6K-green) ![WordPress Plugin Rating](https://img.shields.io/badge/RATING-4.8/5_(61)-green) ![WordPress Plugin: Tested WP Version](https://img.shields.io/badge/WORDPRESS-V6.5_TESTED-orange) ![WordPress Plugin Last Updated](https://img.shields.io/badge/LAST_UPDATED-Aug_2024-orange)
68

79
## Description ##

src/components/DocListing/ArticleChildrens.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import DocActions from '../DocActions';
33
import { __, sprintf } from '@wordpress/i18n';
44
import QuickEditModal from './QuickEditModal';
55
import extractedTitle from '../../utils/extractedTitle';
6+
import UpgradePopup from '../ProPreviews/common/UpgradePopup';
67

78
const ArticleChildrens = ( { article, section, sections, setShowArticles, isAllowComments } ) => {
9+
// Note: Level 3 articles cannot be dragged due to @dnd-kit nested context limitation
10+
// Drag-and-drop only works for Level 2 articles in the root context
11+
812
const { modified: lastModifiedDate, comment_count: commentCount } = article;
913

1014
const formattedDateString = () => {
@@ -22,7 +26,10 @@ const ArticleChildrens = ( { article, section, sections, setShowArticles, isAllo
2226

2327
if ( section ) {
2428
return (
25-
<div key={ section?.id } className="flex items-center bg-white border-b border-[#D9D9D9] py-4">
29+
<div
30+
key={ section?.id }
31+
className="flex items-center bg-white border-b border-[#D9D9D9] py-4"
32+
>
2633
<div className="flex items-center w-full group">
2734
<div className="min-w-0 flex-1 sm:flex sm:items-center sm:justify-between">
2835
<div className="flex items-center">
@@ -75,7 +82,34 @@ const ArticleChildrens = ( { article, section, sections, setShowArticles, isAllo
7582
{ __( 'Draft', 'wedocs' ) }
7683
</div>
7784
) }
85+
</a>
86+
87+
{ /* Add Nested Article Button - Pro Feature */ }
88+
{ ! Boolean( parseInt( isAdminRestrictedArticle ) ) && (
89+
<UpgradePopup className={ `mr-4` }>
90+
<div
91+
className='tooltip cursor-pointer flex items-center justify-center w-3.5 h-3.5'
92+
data-tip={ __( 'Create Nested Article (Pro)', 'wedocs' ) }
93+
>
94+
<span className="items-center dashicons dashicons-plus-alt2 hidden group-hover:inline-flex text-2xl font-medium text-[#d1d5db] hover:text-indigo-700"></span>
95+
</div>
96+
</UpgradePopup>
97+
) }
7898

99+
<a
100+
target="_blank"
101+
href={
102+
! Boolean( parseInt( wp?.hooks?.applyFilters(
103+
'wedocs_check_is_admin_restricted_article',
104+
false,
105+
article?.id
106+
) ) ) ?
107+
`${ weDocsAdminVars.adminUrl }post.php?post=${ article?.id }&action=edit` :
108+
`${ window.location.origin }/?p=${ article?.id }`
109+
}
110+
className={ `${ ! Boolean( parseInt( isAdminRestrictedArticle ) ) ? 'mr-4' : '' } flex items-center flex-shrink-0 text-base group font-medium text-gray-700 !shadow-none` }
111+
rel="noreferrer"
112+
>
79113
{ ! Boolean( parseInt( isAdminRestrictedArticle ) ) && (
80114
<>
81115
<QuickEditModal

src/components/DocListing/DocSections.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const DocSections = ( { docs, section, sections, searchValue } ) => {
175175
className='tooltip cursor-pointer flex items-center justify-center w-3.5 h-3.5'
176176
data-tip={ __( 'Create', 'wedocs' ) }
177177
>
178-
<span className="flex items-center dashicons dashicons-plus-alt2 hidden group-hover:inline-flex text-2xl font-medium text-[#d1d5db] hover:text-indigo-700"></span>
178+
<span className="items-center dashicons dashicons-plus-alt2 hidden group-hover:inline-flex text-2xl font-medium text-[#d1d5db] hover:text-indigo-700"></span>
179179
</div>
180180
</AddArticleModal>
181181
<a
@@ -286,7 +286,7 @@ const DocSections = ( { docs, section, sections, searchValue } ) => {
286286
setNeedSortingStatus={ setNeedSortingStatus }
287287
>
288288
<SortableContext
289-
items={ articles }
289+
items={ articles?.map( a => a.id ) || [] }
290290
strategy={ verticalListSortingStrategy }
291291
>
292292
{ articles?.map( ( article ) => (

src/components/DocListing/SectionArticles.js

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { __, sprintf } from '@wordpress/i18n';
55
import QuickEditModal from './QuickEditModal';
66
import { useSortable } from '@dnd-kit/sortable';
77
import extractedTitle from '../../utils/extractedTitle';
8-
import { Fragment, useState } from '@wordpress/element';
8+
import { Fragment, useState, useEffect } from '@wordpress/element';
99
import { useSelect } from '@wordpress/data';
1010
import docStore from '../../data/docs';
1111
import ArticleChildrens from './ArticleChildrens';
1212
import AddArticleModal from '../AddArticleModal';
13+
import DraggableDocs from '../DraggableDocs';
1314

1415
const SectionArticles = ( { article, articles, isAdmin, section, sections, searchValue, setShowArticles, isAllowComments } ) => {
1516
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
@@ -33,13 +34,53 @@ const SectionArticles = ( { article, articles, isAdmin, section, sections, searc
3334

3435
const articleChildrens = useSelect(
3536
( select ) => select( docStore ).getArticleChildrens( parseInt( article?.id ) ),
37+
[ article?.id ]
38+
);
39+
40+
const [ childrenItems, setChildrenItems ] = useState( articleChildrens || [] );
41+
const [ needSortingStatusLocal, setNeedSortingStatusLocal ] = useState( false );
42+
43+
const sortableStatus = useSelect(
44+
( select ) => select( docStore ).getSortingStatus(),
3645
[]
3746
);
3847

39-
const filteredArticleChildrens = articleChildrens?.filter(
40-
( children ) => children?.title?.rendered?.toLowerCase().includes( searchValue.toLowerCase() )
48+
const needSortableStatus = useSelect(
49+
( select ) => select( docStore ).getNeedSortingStatus(),
50+
[]
4151
);
4252

53+
// Update children items when articleChildren changes
54+
useEffect( () => {
55+
if ( articleChildrens ) {
56+
setChildrenItems( articleChildrens );
57+
}
58+
}, [ articleChildrens, article?.id ] );
59+
60+
// Sync local sorting status with global status
61+
useEffect( () => {
62+
setNeedSortingStatusLocal( needSortableStatus );
63+
}, [ needSortableStatus ] );
64+
65+
// Handle sorting when needed
66+
useEffect( () => {
67+
if ( needSortingStatusLocal && childrenItems.length > 0 ) {
68+
const { dispatch } = wp.data;
69+
dispatch( docStore )
70+
.updateSortingStatus( { sortable_status: sortableStatus, documentations: childrenItems } )
71+
.then( ( result ) => setNeedSortingStatusLocal( result?.sorting ) )
72+
.catch( ( error ) => {
73+
console.error( 'Failed to update sorting status:', error );
74+
} );
75+
}
76+
}, [ needSortingStatusLocal, childrenItems, sortableStatus ] );
77+
78+
const filteredArticleChildrens = searchValue
79+
? childrenItems?.filter(
80+
( children ) => children?.title?.rendered?.toLowerCase().includes( searchValue.toLowerCase() )
81+
)
82+
: childrenItems;
83+
4384
const isAdminRestrictedArticle = wp?.hooks?.applyFilters(
4485
'wedocs_check_is_admin_restricted_article',
4586
false,
@@ -55,13 +96,17 @@ const SectionArticles = ( { article, articles, isAdmin, section, sections, searc
5596
{ ...attributes }
5697
ref={ setNodeRef }
5798
>
58-
<div className={ `pr-3.5 py-0.5 cursor-grab` }>
99+
<div
100+
className={ `pr-3.5 py-0.5 cursor-grab hover:bg-gray-100 rounded transition-colors` }
101+
{ ...listeners }
102+
style={{ touchAction: 'none' }}
103+
>
59104
<svg
60105
width="20"
61106
height="21"
62107
fill="none"
63-
{ ...listeners }
64108
xmlns="http://www.w3.org/2000/svg"
109+
className="pointer-events-none"
65110
>
66111
<path
67112
fillRule="evenodd"
@@ -133,7 +178,7 @@ const SectionArticles = ( { article, articles, isAdmin, section, sections, searc
133178
className='tooltip cursor-pointer flex items-center justify-center w-3.5 h-3.5'
134179
data-tip={ __( 'Create', 'wedocs' ) }
135180
>
136-
<span className="flex items-center dashicons dashicons-plus-alt2 hidden group-hover:inline-flex text-2xl font-medium text-[#d1d5db] hover:text-indigo-700"></span>
181+
<span className="items-center dashicons dashicons-plus-alt2 hidden group-hover:inline-flex text-2xl font-medium text-[#d1d5db] hover:text-indigo-700"></span>
137182
</div>
138183
</AddArticleModal>
139184

@@ -232,7 +277,7 @@ const SectionArticles = ( { article, articles, isAdmin, section, sections, searc
232277
</div>
233278
</div>
234279
<div className="flex items-center gap-5 flex-shrink-0 mt-4 sm:mt-0 sm:ml-5">
235-
<div className="flex items-center gap-1">
280+
<div className="flex items-center gap-3">
236281
{ /* Render admin restriction icon. */ }
237282
{ wp?.hooks?.applyFilters(
238283
'wedocs_article_privacy_action',
@@ -297,21 +342,48 @@ const SectionArticles = ( { article, articles, isAdmin, section, sections, searc
297342
</div>
298343
</div>
299344

345+
{ /* Level 3 children - no DraggableDocs wrapper (nested context doesn't work) */ }
300346
{ !isDragging && ( filteredArticleChildrens?.length > 0 ) && (
301347
<div
302-
style={ style }
303348
className={ `my-1 article-children pl-4 sm:pl-16 bg-white` }
304349
>
305-
{ filteredArticleChildrens?.map( ( childrenDoc ) => (
306-
<ArticleChildrens
307-
section={ article }
308-
sections={ articles }
309-
key={ childrenDoc.id }
310-
article={ childrenDoc }
311-
setShowArticles={ setShowArticles }
312-
isAllowComments={ isAllowComments }
313-
/>
314-
) ) }
350+
{ filteredArticleChildrens?.map( ( childrenDoc ) => {
351+
// Allow pro version to override the article children component
352+
const ChildComponent = wp?.hooks?.applyFilters(
353+
'wedocs_article_children_component',
354+
ArticleChildrens,
355+
{
356+
section: article,
357+
sections: articles,
358+
article: childrenDoc,
359+
setShowArticles: setShowArticles,
360+
isAllowComments: isAllowComments,
361+
searchValue: searchValue,
362+
DocActions: DocActions,
363+
QuickEditModal: QuickEditModal,
364+
AddArticleModal: AddArticleModal,
365+
DraggableDocs: DraggableDocs,
366+
}
367+
);
368+
369+
return (
370+
<ChildComponent
371+
section={ article }
372+
sections={ articles }
373+
key={ childrenDoc.id }
374+
article={ childrenDoc }
375+
setShowArticles={ setShowArticles }
376+
isAllowComments={ isAllowComments }
377+
searchValue={ searchValue }
378+
DocActions={ DocActions }
379+
QuickEditModal={ QuickEditModal }
380+
AddArticleModal={ AddArticleModal }
381+
DraggableDocs={ DraggableDocs }
382+
depth={ 2 }
383+
maxDepth={ 7 }
384+
/>
385+
);
386+
} ) }
315387
</div>
316388
) }
317389
</Fragment>

src/components/DraggableDocs.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
DndContext,
33
closestCenter,
4+
pointerWithin,
45
PointerSensor,
56
useSensor,
67
useSensors,
@@ -11,7 +12,7 @@ import { arrayMove } from '@dnd-kit/sortable';
1112
import { dispatch } from '@wordpress/data';
1213
import docsStore from '../data/docs';
1314

14-
const DraggableDocs = ( { setItems, children, setNeedSortingStatus } ) => {
15+
const DraggableDocs = ( { setItems, children, setNeedSortingStatus, parentId = null } ) => {
1516
const sensors = useSensors(
1617
useSensor( PointerSensor, {
1718
activationConstraint: {
@@ -24,7 +25,7 @@ const DraggableDocs = ( { setItems, children, setNeedSortingStatus } ) => {
2425
const handleDragEnd = ( event ) => {
2526
const { active, over } = event;
2627

27-
if ( active?.id !== over?.id ) {
28+
if ( active?.id !== over?.id && over?.id ) {
2829
setItems( ( elements ) => {
2930
const oldItem = elements.find(
3031
( element ) => element?.id === active?.id
@@ -33,6 +34,12 @@ const DraggableDocs = ( { setItems, children, setNeedSortingStatus } ) => {
3334
const newItem = elements.find(
3435
( element ) => element?.id === over?.id
3536
);
37+
38+
// Only allow reordering if both items exist in the current elements array
39+
if ( !oldItem || !newItem ) {
40+
return elements;
41+
}
42+
3643
const oldIndex = elements.indexOf( oldItem );
3744
const newIndex = elements.indexOf( newItem );
3845
const updatedOrder = arrayMove( elements, oldIndex, newIndex );
@@ -50,12 +57,15 @@ const DraggableDocs = ( { setItems, children, setNeedSortingStatus } ) => {
5057
}
5158
};
5259

60+
// Use pointerWithin for better nested context support
61+
const collisionDetectionStrategy = parentId ? pointerWithin : closestCenter;
62+
5363
return (
5464
<DndContext
5565
sensors={ sensors }
56-
collisionDetection={ closestCenter }
66+
collisionDetection={ collisionDetectionStrategy }
5767
onDragEnd={ handleDragEnd }
58-
class="z-10"
68+
id={ parentId ? `parent-${parentId}` : 'root-context' }
5969
>
6070
{ children }
6171
</DndContext>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { __ } from '@wordpress/i18n';
2+
import Overlay from './common/Overlay';
3+
import Switcher from '../Switcher';
4+
import { useState } from '@wordpress/element';
5+
6+
const SocialShareSettings = ( { settingsData, setSettings } ) => {
7+
const [ showOverlay, setShowOverlay ] = useState( false );
8+
const { general } = settingsData;
9+
const SwitcherComponent = window?.switchComponent || Switcher;
10+
11+
return (
12+
<section>
13+
<div className="shadow sm:rounded-md bg-white min-h-[500px] relative">
14+
<div className="py-4 px-8 sm:px-8 sm:py-4">
15+
<h2 className="text-gray-900 font-medium text-lg">
16+
{ __( 'Social Share', 'wedocs' ) }
17+
</h2>
18+
</div>
19+
<hr className="h-px !bg-gray-200 border-0 dark:!bg-gray-200" />
20+
<div
21+
className="pt-6 pb-20 px-8 grid grid-cols-4 gap-5 relative"
22+
onMouseEnter={ () => setShowOverlay( true ) }
23+
onMouseLeave={ () => setShowOverlay( false ) }
24+
>
25+
<div className='col-span-12' >
26+
<div className="settings-content flex items-center justify-between">
27+
<div className="settings-heading md:min-w-[300px] space-x-2 items-center flex flex-1">
28+
<label
29+
className="block text-sm font-medium text-gray-600"
30+
id="headlessui-listbox-label-social-share"
31+
>
32+
{ __( 'Enable Social Share', 'wedocs' ) }
33+
</label>
34+
<div
35+
className="tooltip cursor-pointer ml-2 z-[9999]"
36+
data-tip={ __(
37+
'Enable social sharing buttons on documentation articles',
38+
'wedocs'
39+
) }
40+
>
41+
<svg
42+
xmlns="http://www.w3.org/2000/svg"
43+
width="18"
44+
height="18"
45+
fill="none"
46+
>
47+
<path
48+
d="M9 16A7 7 0 1 0 9 2a7 7 0 0 0 0 14ZM9 6v4M9 14h.01"
49+
stroke="#6b7280"
50+
strokeWidth="1.5"
51+
strokeLinecap="round"
52+
strokeLinejoin="round"
53+
/>
54+
</svg>
55+
</div>
56+
</div>
57+
<div className="settings-field flex items-center w-full max-w-[490px] ml-auto flex-2">
58+
<div className="flex items-center space-x-2">
59+
<span className="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full font-medium">
60+
PRO
61+
</span>
62+
<SwitcherComponent
63+
name="social_share"
64+
settingsPanel={ general }
65+
settingsData={ settingsData }
66+
setSettings={ setSettings }
67+
panelName={ `general` }
68+
isEnabled={ false }
69+
/>
70+
</div>
71+
</div>
72+
</div>
73+
</div>
74+
<Overlay classes={ `${ showOverlay ? 'flex items-center justify-center' : 'hidden' }` } />
75+
</div>
76+
</div>
77+
</section>
78+
);
79+
};
80+
81+
export default SocialShareSettings;

0 commit comments

Comments
 (0)