← All changes
|
assets/js/tools/editor/shared/editor-shared-utils.js
+0
-70
trunk
→
0.0.13
View file →
| @@ -63,27 +63,8 @@ | ||
| 63 | 63 | ? editor.getCurrentPostId() |
| 64 | 64 | : null; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - // SEC-2 two-tab guard, shared by every handler that writes the open post: a | |
| 68 | - // brain-stamped post id the live editor cannot confirm is a refusal (fail | |
| 69 | - // closed). Returns null when the write may proceed. | |
| 70 | - function postIdRefusal( expectedPostId ) { | |
| 71 | - // eslint-disable-next-line eqeqeq | |
| 72 | - if ( expectedPostId == null ) { | |
| 73 | - return null; | |
| 74 | - } | |
| 75 | - const live = currentPostId(); | |
| 76 | - // eslint-disable-next-line eqeqeq | |
| 77 | - if ( live == null ) { | |
| 78 | - return { reason: 'post_id_unresolvable', detail: 'expected=' + expectedPostId + ',live=null', live: null }; | |
| 79 | - } | |
| 80 | - if ( Number( live ) !== Number( expectedPostId ) ) { | |
| 81 | - return { reason: 'post_id_mismatch', detail: 'expected=' + expectedPostId + ',live=' + live, live }; | |
| 82 | - } | |
| 83 | - return null; | |
| 84 | - } | |
| 85 | - | |
| 86 | 67 | // The live post meta object from the editing session (or {} when absent) — |
| 87 | 68 | // the read side of the session-scoped scripts/styles write. |
| 88 | 69 | function currentMeta( sel ) { |
| 89 | 70 | const meta = sel && sel.getEditedPostAttribute ? sel.getEditedPostAttribute( 'meta' ) : null; |
| @@ -112,53 +93,8 @@ | ||
| 112 | 93 | const order = sel && sel.getBlockOrder ? sel.getBlockOrder() : null; |
| 113 | 94 | return Array.isArray( order ) && order.length > 0 ? order[ 0 ] : null; |
| 114 | 95 | } |
| 115 | 96 | |
| 116 | - // canEditBlock reads lock.edit only. Content shared with other pages (a | |
| 117 | - // synced pattern's or template part's inner blocks, an overridable one | |
| 118 | - // included) is off-limits to an AI op even when no lock attribute says so; | |
| 119 | - // the synced pattern / template part block ITSELF stays editable as a page | |
| 120 | - // block. Editing mode follows the editor: 'disabled' takes nothing (in | |
| 121 | - // zoom-out, every block below a section), 'contentOnly' (an inserted | |
| 122 | - // pattern's blocks, a focused section, a section in zoom-out) takes | |
| 123 | - // attribute and text edits but no structural change. | |
| 124 | - const SHARED_CONTENT_HOSTS = { 'core/block': true, 'core/template-part': true }; | |
| 125 | - function insideSharedContent( sel, id ) { | |
| 126 | - if ( typeof sel.getBlockParents !== 'function' ) { | |
| 127 | - return false; | |
| 128 | - } | |
| 129 | - return ( sel.getBlockParents( id ) || [] ).some( function ( p ) { | |
| 130 | - const b = sel.getBlock( p ); | |
| 131 | - return !! ( b && SHARED_CONTENT_HOSTS[ b.name ] ); | |
| 132 | - } ); | |
| 133 | - } | |
| 134 | - // `structural` = insert / remove / move / replace (anything but an edit of | |
| 135 | - // the block's own attributes). | |
| 136 | - function isAiEditable( sel, id, structural ) { | |
| 137 | - if ( insideSharedContent( sel, id ) ) { | |
| 138 | - return false; | |
| 139 | - } | |
| 140 | - const mode = typeof sel.getBlockEditingMode === 'function' ? sel.getBlockEditingMode( id ) : 'default'; | |
| 141 | - if ( mode === 'disabled' ) { | |
| 142 | - return false; | |
| 143 | - } | |
| 144 | - return ! ( structural && mode === 'contentOnly' ); | |
| 145 | - } | |
| 146 | - // A container accepts AI-added (or moved-in) children unless it is shared | |
| 147 | - // content, sits inside it, or is disabled. A contentOnly root still takes | |
| 148 | - // them, as in core: with "Show template" on, core/post-content itself is | |
| 149 | - // contentOnly and every page section lives under it. | |
| 150 | - function isAiInsertableRoot( sel, root ) { | |
| 151 | - if ( ! root ) { | |
| 152 | - return true; | |
| 153 | - } | |
| 154 | - const b = sel.getBlock( root ); | |
| 155 | - if ( b && SHARED_CONTENT_HOSTS[ b.name ] ) { | |
| 156 | - return false; | |
| 157 | - } | |
| 158 | - return isAiEditable( sel, root, false ); | |
| 159 | - } | |
| 160 | - | |
| 161 | 97 | // The 13 GBS-banned per-block visual styling props. Per-block styling lives in |
| 162 | 98 | // `className` ONLY (the Spectra GBS JIT grammar); these are never authorable |
| 163 | 99 | // attrs even when a block's registry declares them. A sanctioned constant — |
| 164 | 100 | // every OTHER attribute's validity is decided by the registry (getBlockType). |
| @@ -582,9 +518,8 @@ | ||
| 582 | 518 | window.zipwpEditorShared.previewSectionGbs = previewSectionGbs; |
| 583 | 519 | window.zipwpEditorShared.createSectionGbsSaver = createSectionGbsSaver; |
| 584 | 520 | window.zipwpEditorShared.queueSectionGbsForSave = queueSectionGbsForSave; |
| 585 | 521 | window.zipwpEditorShared.currentPostId = currentPostId; |
| 586 | - window.zipwpEditorShared.postIdRefusal = postIdRefusal; | |
| 587 | 522 | window.zipwpEditorShared.editorSelect = editorSelect; |
| 588 | 523 | window.zipwpEditorShared.editorDispatch = editorDispatch; |
| 589 | 524 | window.zipwpEditorShared.currentMeta = currentMeta; |
| 590 | 525 | window.zipwpEditorShared.blockEditorSelect = blockEditorSelect; |
| @@ -589,10 +524,8 @@ | ||
| 589 | 524 | window.zipwpEditorShared.currentMeta = currentMeta; |
| 590 | 525 | window.zipwpEditorShared.blockEditorSelect = blockEditorSelect; |
| 591 | 526 | window.zipwpEditorShared.blockEditorDispatch = blockEditorDispatch; |
| 592 | 527 | window.zipwpEditorShared.rootClientId = rootClientId; |
| 593 | - window.zipwpEditorShared.isAiEditable = isAiEditable; | |
| 594 | - window.zipwpEditorShared.isAiInsertableRoot = isAiInsertableRoot; | |
| 595 | 528 | window.zipwpEditorShared.bannedVisualAttrs = bannedVisualAttrs; |
| 596 | 529 | window.zipwpEditorShared.isBannedVisualAttr = isBannedVisualAttr; |
| 597 | 530 | window.zipwpEditorShared.isJsCapable = isJsCapable; |
| 598 | 531 | window.zipwpEditorShared.referencedIds = referencedIds; |
| @@ -608,9 +541,8 @@ | ||
| 608 | 541 | previewSectionGbs, |
| 609 | 542 | createSectionGbsSaver, |
| 610 | 543 | queueSectionGbsForSave, |
| 611 | 544 | currentPostId, |
| 612 | - postIdRefusal, | |
| 613 | 545 | editorSelect, |
| 614 | 546 | editorDispatch, |
| 615 | 547 | currentMeta, |
| 616 | 548 | blockEditorSelect, |
| @@ -619,10 +551,8 @@ | ||
| 619 | 551 | referencedIds, |
| 620 | 552 | classDependents, |
| 621 | 553 | anchorDependents, |
| 622 | 554 | rootClientId, |
| 623 | - isAiEditable, | |
| 624 | - isAiInsertableRoot, | |
| 625 | 555 | bannedVisualAttrs, |
| 626 | 556 | isBannedVisualAttr, |
| 627 | 557 | }; |
| 628 | 558 | } |