-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {BeClonable} from './be-clonable.js'; | ||
import {def} from 'trans-render/lib/def.js'; | ||
|
||
await BeClonable.bootUp(); | ||
|
||
def('be-clonable', BeClonable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import {register} from 'be-hive/register.js'; | ||
import {tagName } from './be-clonable.js'; | ||
import './be-clonable.js'; | ||
import './behance.js'; | ||
import {BeHive} from 'be-hive/be-hive.js'; | ||
|
||
const ifWantsToBe = 'clonable'; | ||
const upgrade = '*'; | ||
|
||
register(ifWantsToBe, upgrade, tagName); | ||
BeHive.registry.register({ | ||
base: 'be-clonable', | ||
enhPropKey: 'beClonable', | ||
map: { | ||
'0.0': 'ni' | ||
}, | ||
do: { | ||
mount:{ | ||
import: async() => { | ||
const {BeClonable} = await import('./be-clonable.js'); | ||
return BeClonable; | ||
} | ||
} | ||
} | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {BE, propDefaults, propInfo} from 'be-enhanced/BE.js'; | ||
import {BEConfig} from 'be-enhanced/types'; | ||
import {XE} from 'xtal-element/XE.js'; | ||
import {Actions, AllProps, AP, PAP, ProPAP, POA, ProPOA} from '../types'; | ||
|
||
export class BeClonable extends BE<AP, Actions> implements Actions{ | ||
#trigger: WeakRef<HTMLButtonElement> | undefined; | ||
async addCloneBtn(self: this): ProPOA { | ||
if(this.#trigger === undefined){ | ||
//the check above is unlikely to ever fail. | ||
const {triggerInsertPosition, enhancedElement} = self; | ||
const {findAdjacentElement} = await import('trans-render/lib/findAdjacentElement.js'); | ||
const trigger = findAdjacentElement(triggerInsertPosition!, enhancedElement, 'button.be-clonable-trigger'); | ||
if(trigger !== null) this.#trigger = new WeakRef(trigger as HTMLButtonElement); | ||
let byob = true; | ||
if(this.#trigger === undefined){ | ||
byob = false; | ||
const trigger = document.createElement('button'); | ||
trigger.type = 'button'; | ||
trigger.classList.add('be-clonable-trigger'); | ||
trigger.ariaLabel = 'Clone this.'; | ||
trigger.title = 'Clone this.'; | ||
enhancedElement.insertAdjacentElement(triggerInsertPosition!, trigger); | ||
this.#trigger = new WeakRef(trigger); | ||
} | ||
|
||
return [{ | ||
resolved: true, | ||
byob | ||
}, { | ||
beCloned: { | ||
on: 'click', | ||
of: this.#trigger?.deref() | ||
} | ||
}] as POA; | ||
|
||
}else{ | ||
//can't think of a scenario where consumer would want to change the trigger position midstream, so not bothering to do anything here | ||
} | ||
} | ||
|
||
setBtnContent({buttonContent}: this): void { | ||
if(this.#trigger !== undefined){ | ||
this.#trigger.deref()!.innerHTML = buttonContent!; | ||
} | ||
} | ||
|
||
beCloned(self: this): void { | ||
const {enhancedElement, cloneInsertPosition} = self; | ||
const clone = enhancedElement.cloneNode(true) as Element; | ||
enhancedElement.insertAdjacentElement(cloneInsertPosition!, clone); | ||
} | ||
} | ||
|
||
export interface BeClonable extends AP{} | ||
|
||
export const tagName = 'be-clonable'; | ||
|
||
|
||
const xe = new XE<AP, Actions>({ | ||
config: { | ||
tagName, | ||
propDefaults: { | ||
...propDefaults, | ||
byob: true, | ||
triggerInsertPosition: 'beforeend', | ||
cloneInsertPosition: 'afterend', | ||
buttonContent: '❏' | ||
}, | ||
propInfo: { | ||
...propInfo | ||
}, | ||
actions: { | ||
addCloneBtn: { | ||
ifAllOf: ['triggerInsertPosition'], | ||
}, | ||
setBtnContent: { | ||
ifAllOf: ['buttonContent'], | ||
ifNoneOf: ['byob'], | ||
} | ||
} | ||
}, | ||
superclass: BeClonable | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {register} from 'be-hive/register.js'; | ||
import {tagName } from './be-clonable.js'; | ||
import './be-clonable.js'; | ||
|
||
const ifWantsToBe = 'clonable'; | ||
const upgrade = '*'; | ||
|
||
register(ifWantsToBe, upgrade, tagName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters