Skip to content

Commit

Permalink
0.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed May 12, 2024
1 parent 781f9cb commit 09855bb
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 45 deletions.
42 changes: 7 additions & 35 deletions be-clonable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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';
import {config as beCnfg} from 'be-enhanced/config.js';
import {BE, BEConfig} from 'be-enhanced/BE.js';
import {Actions, AllProps, AP, ProPOA, POA} from './types';
import {MountObserver} from 'mount-observer/MountObserver.js';
import {IEnhancement, BEAllProps} from 'trans-render/be/types';

export class BeClonable extends BE<AP, Actions> implements Actions{
export class BeClonable extends BE implements Actions{
#trigger: WeakRef<HTMLButtonElement> | undefined;
async addCloneBtn(self: this): ProPOA {
if(this.#trigger === undefined){
Expand Down Expand Up @@ -52,33 +53,4 @@ export class BeClonable extends BE<AP, Actions> implements Actions{
}
}

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: '&#10063;'
},
propInfo: {
...propInfo
},
actions: {
addCloneBtn: {
ifAllOf: ['triggerInsertPosition'],
},
setBtnContent: {
ifAllOf: ['buttonContent'],
ifNoneOf: ['byob'],
}
}
},
superclass: BeClonable
});
export interface BeClonable extends AP{}
6 changes: 6 additions & 0 deletions behance.ts
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);
24 changes: 17 additions & 7 deletions behivior.ts
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.
84 changes: 84 additions & 0 deletions legacy/be-clonable.ts
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: '&#10063;'
},
propInfo: {
...propInfo
},
actions: {
addCloneBtn: {
ifAllOf: ['triggerInsertPosition'],
},
setBtnContent: {
ifAllOf: ['buttonContent'],
ifNoneOf: ['byob'],
}
}
},
superclass: BeClonable
});
File renamed without changes.
8 changes: 8 additions & 0 deletions legacy/behivior.ts
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);
5 changes: 2 additions & 3 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionOnEventConfigs } from "trans-render/froop/types";
import {IBE} from 'be-enhanced/types';
import { IEnhancement, BEAllProps } from 'trans-render/be/types';

export interface EndUserProps extends IBE{
export interface EndUserProps extends IEnhancement{
triggerInsertPosition?: InsertPosition;
cloneInsertPosition?: InsertPosition;
buttonContent?: string;
Expand All @@ -26,5 +26,4 @@ export interface Actions{
addCloneBtn(self: this): ProPOA;
setBtnContent(self: this): void;
beCloned(self: this): void;
//finale(): void;
}

0 comments on commit 09855bb

Please sign in to comment.