react-align 2.0.5 → 2.2.0
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/dist/env.d.ts +2 -0
- package/dist/index.d.ts +132 -6
- package/dist/react-align.mjs +1236 -0
- package/dist/react-align.umd.js +28 -0
- package/package.json +33 -51
- package/src/GridArea.tsx +83 -63
- package/src/GridItem.tsx +30 -51
- package/src/GridSection.tsx +10 -11
- package/src/GridWrapper.tsx +14 -20
- package/src/Icon/icons.ts +11 -11
- package/src/Icon/index.tsx +5 -5
- package/src/context.tsx +3 -2
- package/src/env.d.ts +2 -0
- package/src/grid.css +18 -19
- package/src/{index.tsx → index.ts} +0 -1
- package/dist/GridArea.d.ts +0 -18
- package/dist/GridItem.d.ts +0 -26
- package/dist/GridSection.d.ts +0 -15
- package/dist/GridWrapper.d.ts +0 -18
- package/dist/Icon/icons.d.ts +0 -14
- package/dist/Icon/index.d.ts +0 -10
- package/dist/context.d.ts +0 -14
- package/dist/index.js +0 -8
- package/dist/react-align.cjs.development.js +0 -615
- package/dist/react-align.cjs.development.js.map +0 -1
- package/dist/react-align.cjs.production.min.js +0 -2
- package/dist/react-align.cjs.production.min.js.map +0 -1
- package/dist/react-align.esm.js +0 -604
- package/dist/react-align.esm.js.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode(".reactalign.wrapper{height:100%;display:flex;justify-content:space-between}.reactalign .section{display:flex;flex-direction:column;justify-content:space-between}.reactalign .area{display:flex;border:0 solid transparent;box-sizing:border-box;border-radius:8px;position:relative}.reactalign .area-transition-in{transition:all .3s ease-in-out,min-height .5s ease-in-out .2s,min-width .5s ease-in-out .2s}.reactalign .area-transition-out{transition:all .3s ease-in-out .4s,min-height .5s ease-in-out .2s,min-width .5s ease-in-out .2s}.reactalign .item{position:relative;border:0 solid transparent;margin:6px;border-radius:6px}.reactalign .stretch{flex:auto}.reactalign .just-centered{justify-content:center}.reactalign .just-end{justify-content:flex-end}.reactalign .middle{align-items:center}.reactalign .bottom{align-items:flex-end}.reactalign .hide{display:none}.reactalign .overlay{position:absolute;top:0;left:0;width:100%;height:100%;box-sizing:border-box;background:rgba(0,0,0,.6)}.reactalign .overlay-buttons{display:flex;padding:6px;box-sizing:border-box;justify-content:space-between}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
|
+
(function(f,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("react"),require("react-beautiful-dnd")):typeof define=="function"&&define.amd?define(["exports","react","react-beautiful-dnd"],i):(f=typeof globalThis!="undefined"?globalThis:f||self,i(f.ReactAlign={},f.React,f.ReactBeautifulDnd))})(this,function(f,i,S){"use strict";var Tr=Object.defineProperty,Pr=Object.defineProperties;var Dr=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable;var ze=(f,i,S)=>i in f?Tr(f,i,{enumerable:!0,configurable:!0,writable:!0,value:S}):f[i]=S,w=(f,i)=>{for(var S in i||(i={}))Ge.call(i,S)&&ze(f,S,i[S]);if(ae)for(var S of ae(i))qe.call(i,S)&&ze(f,S,i[S]);return f},ie=(f,i)=>Pr(f,Dr(i));var Je=(f,i)=>{var S={};for(var A in f)Ge.call(f,A)&&i.indexOf(A)<0&&(S[A]=f[A]);if(f!=null&&ae)for(var A of ae(f))i.indexOf(A)<0&&qe.call(f,A)&&(S[A]=f[A]);return S};const A=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function Ke(n){if(n&&n.__esModule)return n;const C=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const s in n)if(s!=="default"){const E=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(C,s,E.get?E:{enumerable:!0,get:()=>n[s]})}}return C.default=n,Object.freeze(C)}const Ce=A(i),o=Ke(i),Ee=i.createContext({editing:!1,isDragging:!1}),le=()=>i.useContext(Ee),Wr="";var se={exports:{}},H={};/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.production.min.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/var ke;function Xe(){if(ke)return H;ke=1;var n=Ce.default,C=Symbol.for("react.element"),s=Symbol.for("react.fragment"),E=Object.prototype.hasOwnProperty,R=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,v={key:!0,ref:!0,__self:!0,__source:!0};function k(g,d,j){var _,O={},D=null,T=null;j!==void 0&&(D=""+j),d.key!==void 0&&(D=""+d.key),d.ref!==void 0&&(T=d.ref);for(_ in d)E.call(d,_)&&!v.hasOwnProperty(_)&&(O[_]=d[_]);if(g&&g.defaultProps)for(_ in d=g.defaultProps,d)O[_]===void 0&&(O[_]=d[_]);return{$$typeof:C,type:g,key:D,ref:T,props:O,_owner:R.current}}return H.Fragment=s,H.jsx=k,H.jsxs=k,H}var U={};/**
|
|
11
|
+
* @license React
|
|
12
|
+
* react-jsx-runtime.development.js
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*/var ye;function Qe(){return ye||(ye=1,process.env.NODE_ENV!=="production"&&function(){var n=Ce.default,C=Symbol.for("react.element"),s=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),k=Symbol.for("react.provider"),g=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),D=Symbol.for("react.lazy"),T=Symbol.for("react.offscreen"),h=Symbol.iterator,N="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var r=h&&e[h]||e[N];return typeof r=="function"?r:null}var m=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function L(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),a=1;a<r;a++)t[a-1]=arguments[a];z("error",e,t)}}function z(e,r,t){{var a=m.ReactDebugCurrentFrame,c=a.getStackAddendum();c!==""&&(r+="%s",t=t.concat([c]));var p=t.map(function(u){return String(u)});p.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,p)}}var G=!1,q=!1,Z=!1,M=!1,J=!1,we;we=Symbol.for("react.module.reference");function ar(e){return!!(typeof e=="string"||typeof e=="function"||e===E||e===v||J||e===R||e===j||e===_||M||e===T||G||q||Z||typeof e=="object"&&e!==null&&(e.$$typeof===D||e.$$typeof===O||e.$$typeof===k||e.$$typeof===g||e.$$typeof===d||e.$$typeof===we||e.getModuleId!==void 0))}function ir(e,r,t){var a=e.displayName;if(a)return a;var c=r.displayName||r.name||"";return c!==""?t+"("+c+")":t}function be(e){return e.displayName||"Context"}function F(e){if(e==null)return null;if(typeof e.tag=="number"&&L("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case E:return"Fragment";case s:return"Portal";case v:return"Profiler";case R:return"StrictMode";case j:return"Suspense";case _:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case g:var r=e;return be(r)+".Consumer";case k:var t=e;return be(t._context)+".Provider";case d:return ir(e,e.render,"ForwardRef");case O:var a=e.displayName||null;return a!==null?a:F(e.type)||"Memo";case D:{var c=e,p=c._payload,u=c._init;try{return F(u(p))}catch(l){return null}}}return null}var $=Object.assign,K=0,_e,Se,Re,xe,je,Me,Oe;function Te(){}Te.__reactDisabledLog=!0;function lr(){{if(K===0){_e=console.log,Se=console.info,Re=console.warn,xe=console.error,je=console.group,Me=console.groupCollapsed,Oe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Te,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}K++}}function sr(){{if(K--,K===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:$({},e,{value:_e}),info:$({},e,{value:Se}),warn:$({},e,{value:Re}),error:$({},e,{value:xe}),group:$({},e,{value:je}),groupCollapsed:$({},e,{value:Me}),groupEnd:$({},e,{value:Oe})})}K<0&&L("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var fe=m.ReactCurrentDispatcher,de;function ee(e,r,t){{if(de===void 0)try{throw Error()}catch(c){var a=c.stack.trim().match(/\n( *(at )?)/);de=a&&a[1]||""}return`
|
|
19
|
+
`+de+e}}var pe=!1,re;{var ur=typeof WeakMap=="function"?WeakMap:Map;re=new ur}function Pe(e,r){if(!e||pe)return"";{var t=re.get(e);if(t!==void 0)return t}var a;pe=!0;var c=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var p;p=fe.current,fe.current=null,lr();try{if(r){var u=function(){throw Error()};if(Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(I){a=I}Reflect.construct(e,[],u)}else{try{u.call()}catch(I){a=I}e.call(u.prototype)}}else{try{throw Error()}catch(I){a=I}e()}}catch(I){if(I&&a&&typeof I.stack=="string"){for(var l=I.stack.split(`
|
|
20
|
+
`),P=a.stack.split(`
|
|
21
|
+
`),y=l.length-1,b=P.length-1;y>=1&&b>=0&&l[y]!==P[b];)b--;for(;y>=1&&b>=0;y--,b--)if(l[y]!==P[b]){if(y!==1||b!==1)do if(y--,b--,b<0||l[y]!==P[b]){var W=`
|
|
22
|
+
`+l[y].replace(" at new "," at ");return e.displayName&&W.includes("<anonymous>")&&(W=W.replace("<anonymous>",e.displayName)),typeof e=="function"&&re.set(e,W),W}while(y>=1&&b>=0);break}}}finally{pe=!1,fe.current=p,sr(),Error.prepareStackTrace=c}var B=e?e.displayName||e.name:"",Ue=B?ee(B):"";return typeof e=="function"&&re.set(e,Ue),Ue}function cr(e,r,t){return Pe(e,!1)}function fr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function te(e,r,t){if(e==null)return"";if(typeof e=="function")return Pe(e,fr(e));if(typeof e=="string")return ee(e);switch(e){case j:return ee("Suspense");case _:return ee("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return cr(e.render);case O:return te(e.type,r,t);case D:{var a=e,c=a._payload,p=a._init;try{return te(p(c),r,t)}catch(u){}}}return""}var ne=Object.prototype.hasOwnProperty,De={},We=m.ReactDebugCurrentFrame;function oe(e){if(e){var r=e._owner,t=te(e.type,e._source,r?r.type:null);We.setExtraStackFrame(t)}else We.setExtraStackFrame(null)}function dr(e,r,t,a,c){{var p=Function.call.bind(ne);for(var u in e)if(p(e,u)){var l=void 0;try{if(typeof e[u]!="function"){var P=Error((a||"React class")+": "+t+" type `"+u+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[u]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw P.name="Invariant Violation",P}l=e[u](r,u,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(y){l=y}l&&!(l instanceof Error)&&(oe(c),L("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",a||"React class",t,u,typeof l),oe(null)),l instanceof Error&&!(l.message in De)&&(De[l.message]=!0,oe(c),L("Failed %s type: %s",t,l.message),oe(null))}}}var pr=Array.isArray;function ve(e){return pr(e)}function vr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function hr(e){try{return Ae(e),!1}catch(r){return!0}}function Ae(e){return""+e}function Ve(e){if(hr(e))return L("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",vr(e)),Ae(e)}var X=m.ReactCurrentOwner,gr={key:!0,ref:!0,__self:!0,__source:!0},Fe,Ie,he;he={};function Lr(e){if(ne.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function mr(e){if(ne.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Cr(e,r){if(typeof e.ref=="string"&&X.current&&r&&X.current.stateNode!==r){var t=F(X.current.type);he[t]||(L('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',F(X.current.type),e.ref),he[t]=!0)}}function Er(e,r){{var t=function(){Fe||(Fe=!0,L("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function kr(e,r){{var t=function(){Ie||(Ie=!0,L("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var yr=function(e,r,t,a,c,p,u){var l={$$typeof:C,type:e,key:r,ref:t,props:u,_owner:p};return l._store={},Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:c}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l};function wr(e,r,t,a,c){{var p,u={},l=null,P=null;t!==void 0&&(Ve(t),l=""+t),mr(r)&&(Ve(r.key),l=""+r.key),Lr(r)&&(P=r.ref,Cr(r,c));for(p in r)ne.call(r,p)&&!gr.hasOwnProperty(p)&&(u[p]=r[p]);if(e&&e.defaultProps){var y=e.defaultProps;for(p in y)u[p]===void 0&&(u[p]=y[p])}if(l||P){var b=typeof e=="function"?e.displayName||e.name||"Unknown":e;l&&Er(u,b),P&&kr(u,b)}return yr(e,l,P,c,a,X.current,u)}}var ge=m.ReactCurrentOwner,Ne=m.ReactDebugCurrentFrame;function Y(e){if(e){var r=e._owner,t=te(e.type,e._source,r?r.type:null);Ne.setExtraStackFrame(t)}else Ne.setExtraStackFrame(null)}var Le;Le=!1;function me(e){return typeof e=="object"&&e!==null&&e.$$typeof===C}function Ze(){{if(ge.current){var e=F(ge.current.type);if(e)return`
|
|
23
|
+
|
|
24
|
+
Check the render method of \``+e+"`."}return""}}function br(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
|
|
25
|
+
|
|
26
|
+
Check your code at `+r+":"+t+"."}return""}}var $e={};function _r(e){{var r=Ze();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
27
|
+
|
|
28
|
+
Check the top-level render call using <`+t+">.")}return r}}function Ye(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=_r(r);if($e[t])return;$e[t]=!0;var a="";e&&e._owner&&e._owner!==ge.current&&(a=" It was passed a child from "+F(e._owner.type)+"."),Y(e),L('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,a),Y(null)}}function Be(e,r){{if(typeof e!="object")return;if(ve(e))for(var t=0;t<e.length;t++){var a=e[t];me(a)&&Ye(a,r)}else if(me(e))e._store&&(e._store.validated=!0);else if(e){var c=V(e);if(typeof c=="function"&&c!==e.entries)for(var p=c.call(e),u;!(u=p.next()).done;)me(u.value)&&Ye(u.value,r)}}}function Sr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===d||r.$$typeof===O))t=r.propTypes;else return;if(t){var a=F(r);dr(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!Le){Le=!0;var c=F(r);L("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",c||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&L("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Rr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var a=r[t];if(a!=="children"&&a!=="key"){Y(e),L("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),Y(null);break}}e.ref!==null&&(Y(e),L("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}function He(e,r,t,a,c,p){{var u=ar(e);if(!u){var l="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(l+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var P=br(c);P?l+=P:l+=Ze();var y;e===null?y="null":ve(e)?y="array":e!==void 0&&e.$$typeof===C?(y="<"+(F(e.type)||"Unknown")+" />",l=" Did you accidentally export a JSX literal instead of a component?"):y=typeof e,L("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",y,l)}var b=wr(e,r,t,c,p);if(b==null)return b;if(u){var W=r.children;if(W!==void 0)if(a)if(ve(W)){for(var B=0;B<W.length;B++)Be(W[B],e);Object.freeze&&Object.freeze(W)}else L("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Be(W,e)}return e===E?Rr(b):Sr(b),b}}function xr(e,r,t){return He(e,r,t,!0)}function jr(e,r,t){return He(e,r,t,!1)}var Mr=jr,Or=xr;U.Fragment=E,U.jsx=Mr,U.jsxs=Or}()),U}(function(n){process.env.NODE_ENV==="production"?n.exports=Xe():n.exports=Qe()})(se);const x=se.exports.jsx,ue=se.exports.jsxs,er=({className:n,children:C,editing:s,vertical:E,stretch:R,style:v,editorStyle:k,onMove:g,onAlignChange:d,onExtend:j})=>{const[_,O]=i.useState(!1),D=i.useCallback(()=>{O(!0)},[]),T=i.useCallback((h,N)=>{O(!1),!(!h.destination||h.reason!=="DROP"||h.destination.droppableId===h.source.droppableId&&h.destination.index===h.source.index)&&(g==null||g(h.draggableId,h.destination.droppableId,h.destination.index,h.source.droppableId,h.source.index))},[g]);return x("div",{className:["reactalign","wrapper",n,E&&"vertical",R&&"stretch"].filter(Boolean).join(" "),style:s?k:v,children:x(S.DragDropContext,{onDragStart:D,onDragEnd:T,children:x(Ee.Provider,{value:{editing:!!s,onAlignChange:d,onExtend:j,isDragging:_},children:C})})})},rr=({className:n,children:C,horizontal:s,stretch:E,fixedWidth:R,fixedHeight:v,style:k,editorStyle:g})=>{const{editing:d}=le();return x("div",{className:`section ${n} ${s?"horizontal":""} ${E?"stretch":""}`,style:w(w(w({},d?g:k),typeof v=="number"?{height:v+"px"}:{}),typeof R=="number"?{width:R+"px"}:{}),children:C})},tr={horizontalExtend:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("path",{d:"M0.999999 20.25L1 3.75",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M23 20.25L23 3.75",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 12L20.5 12",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M17.5 9L20.5 12L17.5 15",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 12L4 12",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M7 15L4 12L7 9",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"})),horizontalNormal:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("path",{d:"M1 12L6 12",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M3 9L6 12L3 15",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M23 12L18 12",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M21 15L18 12L21 9",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("rect",{x:8.75,y:2.75,width:6.5,height:18.5,rx:1.25,stroke:"currentColor",strokeWidth:1.5})),verticalExtend:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("path",{d:"M3.75 0.999999L20.25 1",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M3.75 23L20.25 23",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 12L12 20.5",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M15 17.5L12 20.5L9 17.5",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 12L12 4",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M9 7L12 4L15 7",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"})),verticalNormal:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("path",{d:"M12 1L12 6",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M15 3L12 6L9 3",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 23L12 18",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M9 21L12 18L15 21",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("rect",{x:21.25,y:8.75,width:6.5,height:18.5,rx:1.25,transform:"rotate(90 21.25 8.75)",stroke:"currentColor",strokeWidth:1.5})),moveArrows:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("path",{d:"M14.6514 19.0977L11.9998 21.7493L9.34814 19.0977",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 15V21.75",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M9.34814 4.90163L11.9998 2.25L14.6514 4.90163",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M12 9V2.25",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M4.90163 14.6509L2.25 11.9993L4.90163 9.34766",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M9 12H2.25",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M19.0981 9.34766L21.7498 11.9993L19.0981 14.6509",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{d:"M15 12H21.75",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"})),alignStart:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{width:24,height:24,rx:4,fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5 5H19V19H5V5ZM4 4H5H19H20V5V19V20H19H5H4V19V5V4ZM6 10C6 9.44772 6.44772 9 7 9C7.55228 9 8 9.44772 8 10V14C8 14.5523 7.55228 15 7 15C6.44772 15 6 14.5523 6 14V10ZM9 10C9 9.44772 9.44772 9 10 9C10.5523 9 11 9.44772 11 10V14C11 14.5523 10.5523 15 10 15C9.44772 15 9 14.5523 9 14V10ZM13 9C12.4477 9 12 9.44772 12 10V14C12 14.5523 12.4477 15 13 15C13.5523 15 14 14.5523 14 14V10C14 9.44772 13.5523 9 13 9Z",fill:"currentColor"})),alignCenter:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{width:24,height:24,rx:4,fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19 19L5 19L5 5L19 5L19 19ZM20 20L19 20L5 20L4 20L4 19L4 5L4 4L5 4L19 4L20 4L20 5L20 19L20 20ZM16 14C16 14.5523 15.5523 15 15 15C14.4477 15 14 14.5523 14 14L14 10C14 9.44772 14.4477 9 15 9C15.5523 9 16 9.44771 16 10L16 14ZM13 14C13 14.5523 12.5523 15 12 15C11.4477 15 11 14.5523 11 14L11 10C11 9.44771 11.4477 9 12 9C12.5523 9 13 9.44771 13 10L13 14ZM9 15C9.55228 15 10 14.5523 10 14L10 10C10 9.44771 9.55228 9 9 9C8.44771 9 8 9.44771 8 10L8 14C8 14.5523 8.44772 15 9 15Z",fill:"currentColor"})),alignEnd:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{width:24,height:24,rx:4,fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19 19L5 19L5 5L19 5L19 19ZM20 20L19 20L5 20L4 20L4 19L4 5L4 4L5 4L19 4L20 4L20 5L20 19L20 20ZM18 14C18 14.5523 17.5523 15 17 15C16.4477 15 16 14.5523 16 14L16 10C16 9.44772 16.4477 9 17 9C17.5523 9 18 9.44771 18 10L18 14ZM15 14C15 14.5523 14.5523 15 14 15C13.4477 15 13 14.5523 13 14L13 10C13 9.44772 13.4477 9 14 9C14.5523 9 15 9.44772 15 10L15 14ZM11 15C11.5523 15 12 14.5523 12 14L12 10C12 9.44772 11.5523 9 11 9C10.4477 9 10 9.44772 10 10L10 14C10 14.5523 10.4477 15 11 15Z",fill:"currentColor"})),alignStartV:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{y:24,width:24,height:24,rx:4,transform:"rotate(-90 0 24)",fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19 5L19 19L5 19L5 5L19 5ZM20 4L20 5L20 19L20 20L19 20L5 20L4 20L4 19L4 5L4 4L5 4L19 4L20 4ZM14 6C14.5523 6 15 6.44772 15 7C15 7.55229 14.5523 8 14 8L10 8C9.44772 8 9 7.55229 9 7C9 6.44772 9.44772 6 10 6L14 6ZM14 9C14.5523 9 15 9.44772 15 10C15 10.5523 14.5523 11 14 11L10 11C9.44772 11 9 10.5523 9 10C9 9.44772 9.44772 9 10 9L14 9ZM15 13C15 12.4477 14.5523 12 14 12L10 12C9.44772 12 9 12.4477 9 13C9 13.5523 9.44772 14 10 14L14 14C14.5523 14 15 13.5523 15 13Z",fill:"currentColor"})),alignCenterV:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{y:24,width:24,height:24,rx:4,transform:"rotate(-90 0 24)",fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19 5L19 19L5 19L5 5L19 5ZM20 4L20 5L20 19L20 20L19 20L5 20L4 20L4 19L4 5L4 4L5 4L19 4L20 4ZM14 8C14.5523 8 15 8.44772 15 9C15 9.55228 14.5523 10 14 10L10 10C9.44772 10 9 9.55229 9 9C9 8.44772 9.44771 8 10 8L14 8ZM14 11C14.5523 11 15 11.4477 15 12C15 12.5523 14.5523 13 14 13L10 13C9.44772 13 9 12.5523 9 12C9 11.4477 9.44771 11 10 11L14 11ZM15 15C15 14.4477 14.5523 14 14 14L10 14C9.44772 14 9 14.4477 9 15C9 15.5523 9.44772 16 10 16L14 16C14.5523 16 15 15.5523 15 15Z",fill:"currentColor"})),alignEndV:n=>o.createElement("svg",w({width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),o.createElement("rect",{y:24,width:24,height:24,rx:4,transform:"rotate(-90 0 24)",fill:"black",fillOpacity:.5}),o.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5 19L5 5L19 5L19 19L5 19ZM4 20L4 19L4 5L4 4L5 4L19 4L20 4L20 5L20 19L20 20L19 20L5 20L4 20ZM10 18C9.44772 18 9 17.5523 9 17C9 16.4477 9.44772 16 10 16L14 16C14.5523 16 15 16.4477 15 17C15 17.5523 14.5523 18 14 18L10 18ZM10 15C9.44772 15 9 14.5523 9 14C9 13.4477 9.44771 13 10 13L14 13C14.5523 13 15 13.4477 15 14C15 14.5523 14.5523 15 14 15L10 15ZM9 11C9 11.5523 9.44771 12 10 12L14 12C14.5523 12 15 11.5523 15 11C15 10.4477 14.5523 10 14 10L10 10C9.44771 10 9 10.4477 9 11Z",fill:"currentColor"}))},Q=({className:n,name:C,onClick:s})=>{const E=tr[C];return x(E,{className:n,onClick:s})},ce=["start","centered","end"];function nr({id:n,className:C,vertical:s,stretch:E,middle:R,bottom:v,disabled:k,align:g,realignable:d,children:j,style:_,editorStyle:O,iconColor:D="#FFFFFF",onAlignChange:T,onClick:h}){const[N,V]=i.useState(!1);i.useEffect(()=>{const M=requestAnimationFrame(()=>V(!0));return()=>{cancelAnimationFrame(M),V(!1)}},[]);const{editing:m,onAlignChange:L}=le(),z=i.useCallback(()=>{if(!d)return;const M=ce[(g?ce.indexOf(g)+1:0)%ce.length];T==null||T(M),L==null||L(n,M)},[g,d,T,L,n]),G=i.useCallback(()=>{!m||h==null||h(n)},[n,m,h]),q=i.useMemo(()=>({position:"absolute",left:s?v?0:void 0:"50%",right:s?v?void 0:0:"50%",bottom:!s&&!v?0:s?"50%":void 0,top:s?"50%":v?0:void 0,opacity:!k&&m&&d?1:0,pointerEvents:!k&&m&&d?"auto":"none",transition:"all 0.5s ease-in-out"}),[s,v,k,m,d]),Z=i.useMemo(()=>i.Children.map(j,M=>i.cloneElement(M,{bottom:v,vertical:s})),[j,v,s]);return N?x(S.Droppable,{droppableId:n,direction:s?"vertical":"horizontal",isDropDisabled:k,children:(M,J)=>ue("div",ie(w({ref:M.innerRef},M.droppableProps),{className:[C,"area",E&&"stretch",R&&"middle",v&&"bottom",g==="centered"?"just-centered":g==="end"?"just-end":"start",m?"area-transition-in":"area-transition-out"].filter(Boolean).join(" "),style:w({flexDirection:s?"column":"row",minHeight:!i.Children.count(j)&&!m?"0px":"26px",minWidth:!i.Children.count(j)&&!m?"0px":"46px",opacity:J.isDraggingOver?.8:1},m?O:_),onClick:G,children:[Z,M.placeholder,x("div",{style:q,children:x("div",{onClick:z,style:{cursor:"pointer",color:D},children:x(Q,{name:g==="centered"?s?"alignCenterV":"alignCenter":g==="end"?s?"alignEndV":"alignEnd":s?"alignStartV":"alignStart"})})})]}))}):null}function or(O){var D=O,{className:n,children:C,id:s,index:E,extendable:R=!1,extended:v=!1,disabled:k=!1,style:g,editorStyle:d,iconColor:j="rgb(255, 255, 255)"}=D,_=Je(D,["className","children","id","index","extendable","extended","disabled","style","editorStyle","iconColor"]);const{vertical:T}=_,{editing:h,isDragging:N,onExtend:V}=le(),[m,L]=i.useState(!1),z=i.useCallback(()=>{!R||(L(!1),V==null||V(s,!v))},[R,V,v,s]),G=i.useMemo(()=>({alignItems:"start",float:"left",color:j}),[j]),q=i.useMemo(()=>({id:s,editing:h,isDragging:N,isHovered:m,extended:v,extendable:R,disabled:k,index:E}),[k,h,R,v,s,E,N,m]);return x(S.Draggable,{draggableId:s,index:E,isDragDisabled:k,children:(Z,M)=>x("div",ie(w({ref:Z.innerRef},Z.draggableProps),{className:`${n} item`,style:w(w({flex:v&&!M.isDragging?"auto":void 0,opacity:M.isDragging?.5:1},h?d:g),Z.draggableProps.style),children:ue("div",{style:{display:"inline-block",position:"relative",minHeight:m&&!k?"35px":void 0,width:!T&&v?"100%":void 0,minWidth:m&&!k?R?"70px":"35px":void 0,height:T&&v?"100%":void 0},onMouseEnter:()=>h&&L(!0),onMouseLeave:()=>h&&L(!1),onClick:J=>J.stopPropagation(),children:[typeof C=="function"?C(q):C,x("div",{className:"overlay",style:{display:!k&&h&&m&&(M.isDragging||!N)?"block":"none"},children:ue("div",{className:"overlay-buttons",style:G,children:[x("div",ie(w({},Z.dragHandleProps),{style:{cursor:"grab"},children:x(Q,{name:"moveArrows"})})),R&&x("div",{style:{cursor:"pointer",marginLeft:"8px"},onClick:z,children:x(Q,{name:T?"verticalExtend":"horizontalExtend"})})]})})]})}))})}f.GridArea=nr,f.GridItem=or,f.GridSection=rr,f.GridWrapper=er,f.Icon=Q,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-align",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"author": "KaWaite",
|
|
5
|
-
"module": "dist/react-align.esm.js",
|
|
6
5
|
"license": "MIT",
|
|
7
|
-
"main": "dist/
|
|
8
|
-
"
|
|
6
|
+
"main": "./dist/react-align.umd.js",
|
|
7
|
+
"module": "./dist/react-align.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/react-align.mjs",
|
|
12
|
+
"require": "./dist/react-align.umd.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
9
15
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"test": "
|
|
13
|
-
"lint": "
|
|
14
|
-
"prepare": "tsdx build",
|
|
15
|
-
"size": "size-limit",
|
|
16
|
-
"analyze": "size-limit --why",
|
|
17
|
-
"storybook": "start-storybook -p 6006",
|
|
18
|
-
"build-storybook": "build-storybook"
|
|
16
|
+
"build": "tsc && vite build",
|
|
17
|
+
"type": "tsc",
|
|
18
|
+
"test": "vitest",
|
|
19
|
+
"lint": "eslint ."
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"dist",
|
|
@@ -25,51 +26,32 @@
|
|
|
25
26
|
"node": ">=10"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"react": ">=16"
|
|
29
|
-
|
|
30
|
-
"husky": {
|
|
31
|
-
"hooks": {
|
|
32
|
-
"pre-commit": "tsdx lint"
|
|
33
|
-
}
|
|
29
|
+
"react": ">=16",
|
|
30
|
+
"react-beautiful-dnd": "*"
|
|
34
31
|
},
|
|
35
32
|
"prettier": {
|
|
36
33
|
"printWidth": 80,
|
|
37
34
|
"semi": true,
|
|
38
|
-
"singleQuote": true,
|
|
39
35
|
"trailingComma": "es5"
|
|
40
36
|
},
|
|
41
|
-
"size-limit": [
|
|
42
|
-
{
|
|
43
|
-
"path": "dist/react-align.cjs.production.min.js",
|
|
44
|
-
"limit": "10 KB"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"path": "dist/react-align.esm.js",
|
|
48
|
-
"limit": "10 KB"
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
37
|
"devDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@size-limit/preset-small-lib": "^6.0.3",
|
|
54
|
-
"@svgr/rollup": "^5.5.0",
|
|
55
|
-
"@types/react": "^17.0.33",
|
|
38
|
+
"@types/react": "^18.0.24",
|
|
56
39
|
"@types/react-beautiful-dnd": "^13.1.2",
|
|
57
|
-
"@types/react-dom": "^
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"react
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"react-beautiful-dnd": "^13.1.0"
|
|
40
|
+
"@types/react-dom": "^18.0.8",
|
|
41
|
+
"@vitejs/plugin-react": "^2.2.0",
|
|
42
|
+
"eslint": "^8.26.0",
|
|
43
|
+
"eslint-config-reearth": "^0.2.1",
|
|
44
|
+
"husky": "^8.0.1",
|
|
45
|
+
"postcss": "^8.4.18",
|
|
46
|
+
"prettier": "^2.7.1",
|
|
47
|
+
"react": "^18.2.0",
|
|
48
|
+
"react-beautiful-dnd": "^13.1.1",
|
|
49
|
+
"react-dom": "^18.2.0",
|
|
50
|
+
"typescript": "^4.8.4",
|
|
51
|
+
"vite": "^3.2.1",
|
|
52
|
+
"vite-plugin-css-injected-by-js": "^2.1.1",
|
|
53
|
+
"vite-plugin-dts": "^1.6.6",
|
|
54
|
+
"vite-plugin-svgr": "^2.2.2",
|
|
55
|
+
"vitest": "^0.24.3"
|
|
74
56
|
}
|
|
75
57
|
}
|
package/src/GridArea.tsx
CHANGED
|
@@ -1,144 +1,164 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
2
|
CSSProperties,
|
|
3
3
|
PropsWithChildren,
|
|
4
4
|
useCallback,
|
|
5
5
|
useMemo,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
useState,
|
|
7
|
+
useEffect,
|
|
8
|
+
cloneElement,
|
|
9
|
+
Children,
|
|
10
|
+
ReactElement,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { Droppable } from "react-beautiful-dnd";
|
|
8
13
|
|
|
9
|
-
import { useAlignContext } from
|
|
10
|
-
import Icon from
|
|
11
|
-
import
|
|
14
|
+
import { useAlignContext } from "./context";
|
|
15
|
+
import Icon from "./Icon";
|
|
16
|
+
import "./grid.css";
|
|
12
17
|
|
|
13
|
-
export type Alignment =
|
|
18
|
+
export type Alignment = "start" | "centered" | "end";
|
|
14
19
|
|
|
15
20
|
export type AreaProps = {
|
|
16
21
|
id: string;
|
|
17
22
|
className?: string;
|
|
18
23
|
vertical?: boolean;
|
|
19
24
|
stretch?: boolean;
|
|
20
|
-
|
|
25
|
+
middle?: boolean;
|
|
26
|
+
bottom?: boolean;
|
|
21
27
|
align?: Alignment;
|
|
28
|
+
realignable?: boolean;
|
|
22
29
|
disabled?: boolean;
|
|
23
30
|
/** Extra customizable parts only for the really picky */
|
|
24
31
|
style?: CSSProperties;
|
|
25
32
|
editorStyle?: CSSProperties;
|
|
26
33
|
iconColor?: string;
|
|
27
34
|
onAlignChange?: (alignment: Alignment) => void;
|
|
35
|
+
onClick?: (id?: string) => void;
|
|
28
36
|
};
|
|
29
37
|
|
|
30
|
-
const alignments = [
|
|
38
|
+
const alignments = ["start", "centered", "end"] as const;
|
|
31
39
|
|
|
32
40
|
export default function GridArea({
|
|
33
41
|
id,
|
|
34
42
|
className,
|
|
35
43
|
vertical,
|
|
36
44
|
stretch,
|
|
37
|
-
|
|
45
|
+
middle,
|
|
46
|
+
bottom,
|
|
38
47
|
disabled,
|
|
39
48
|
align,
|
|
40
|
-
|
|
49
|
+
realignable,
|
|
41
50
|
children,
|
|
42
51
|
// Picky stuff
|
|
43
52
|
style,
|
|
44
53
|
editorStyle,
|
|
45
|
-
iconColor =
|
|
54
|
+
iconColor = "#FFFFFF",
|
|
55
|
+
onAlignChange,
|
|
56
|
+
onClick,
|
|
46
57
|
}: PropsWithChildren<AreaProps>) {
|
|
58
|
+
// ***** Keeps everything working inside dev environment with React 18 StrictMode *****
|
|
59
|
+
const [enableDrop, setEnableDrop] = useState(false);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const animation = requestAnimationFrame(() => setEnableDrop(true));
|
|
63
|
+
|
|
64
|
+
return () => {
|
|
65
|
+
cancelAnimationFrame(animation);
|
|
66
|
+
setEnableDrop(false);
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
// ***** Keeps everything working inside dev environment with React 18 StrictMode *****
|
|
70
|
+
|
|
47
71
|
const { editing: enabled, onAlignChange: onAlignChange2 } = useAlignContext();
|
|
48
72
|
|
|
49
73
|
const handleAlignChange = useCallback(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(align ? alignments.indexOf(align) + 1 : 0) % alignments.length
|
|
53
|
-
];
|
|
74
|
+
if (!realignable) return;
|
|
75
|
+
const a = alignments[(align ? alignments.indexOf(align) + 1 : 0) % alignments.length];
|
|
54
76
|
onAlignChange?.(a);
|
|
55
77
|
onAlignChange2?.(id, a);
|
|
56
|
-
}, [align, onAlignChange, onAlignChange2, id]);
|
|
78
|
+
}, [align, realignable, onAlignChange, onAlignChange2, id]);
|
|
79
|
+
|
|
80
|
+
const handleClick = useCallback(() => {
|
|
81
|
+
if (!enabled) return;
|
|
82
|
+
onClick?.(id);
|
|
83
|
+
}, [id, enabled, onClick]);
|
|
57
84
|
|
|
58
85
|
const buttonStyle: CSSProperties = useMemo(
|
|
59
86
|
() => ({
|
|
60
|
-
position:
|
|
61
|
-
left: vertical ? (
|
|
62
|
-
right: vertical ? (!
|
|
63
|
-
bottom: !vertical && !
|
|
64
|
-
top: vertical ?
|
|
65
|
-
opacity: !disabled && enabled &&
|
|
66
|
-
pointerEvents: !disabled && enabled &&
|
|
67
|
-
transition:
|
|
87
|
+
position: "absolute",
|
|
88
|
+
left: vertical ? (bottom ? 0 : undefined) : "50%",
|
|
89
|
+
right: vertical ? (!bottom ? 0 : undefined) : "50%",
|
|
90
|
+
bottom: !vertical && !bottom ? 0 : vertical ? "50%" : undefined,
|
|
91
|
+
top: vertical ? "50%" : bottom ? 0 : undefined,
|
|
92
|
+
opacity: !disabled && enabled && realignable ? 1 : 0,
|
|
93
|
+
pointerEvents: !disabled && enabled && realignable ? "auto" : "none",
|
|
94
|
+
transition: "all 0.5s ease-in-out",
|
|
68
95
|
}),
|
|
69
|
-
[vertical,
|
|
96
|
+
[vertical, bottom, disabled, enabled, realignable],
|
|
70
97
|
);
|
|
71
98
|
|
|
72
99
|
// Rebuilds the GridItem children to receive their parent GridArea's 'end' and 'vertical' values.
|
|
73
100
|
// Used to know where to align the overlay buttons (end) and how to extend the GridItems (vertical).
|
|
74
101
|
const childrenWithParentProps = useMemo(
|
|
75
102
|
() =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
103
|
+
Children.map(children, child =>
|
|
104
|
+
cloneElement(child as ReactElement<any>, {
|
|
105
|
+
bottom,
|
|
79
106
|
vertical,
|
|
80
|
-
})
|
|
107
|
+
}),
|
|
81
108
|
),
|
|
82
|
-
[children,
|
|
109
|
+
[children, bottom, vertical],
|
|
83
110
|
);
|
|
84
111
|
|
|
85
|
-
return (
|
|
112
|
+
return enableDrop ? (
|
|
86
113
|
<Droppable
|
|
87
114
|
droppableId={id}
|
|
88
|
-
direction={vertical ?
|
|
89
|
-
isDropDisabled={disabled}
|
|
90
|
-
>
|
|
115
|
+
direction={vertical ? "vertical" : "horizontal"}
|
|
116
|
+
isDropDisabled={disabled}>
|
|
91
117
|
{(provided, snapshot) => (
|
|
92
118
|
<div
|
|
93
119
|
ref={provided.innerRef}
|
|
94
120
|
{...provided.droppableProps}
|
|
95
121
|
className={[
|
|
96
122
|
className,
|
|
97
|
-
|
|
98
|
-
stretch &&
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
? 'just-end'
|
|
104
|
-
: 'start',
|
|
105
|
-
enabled ? 'area-transition-in' : 'area-transition-out',
|
|
123
|
+
"area",
|
|
124
|
+
stretch && "stretch",
|
|
125
|
+
middle && "middle",
|
|
126
|
+
bottom && "bottom",
|
|
127
|
+
align === "centered" ? "just-centered" : align === "end" ? "just-end" : "start",
|
|
128
|
+
enabled ? "area-transition-in" : "area-transition-out",
|
|
106
129
|
]
|
|
107
130
|
.filter(Boolean)
|
|
108
|
-
.join(
|
|
131
|
+
.join(" ")}
|
|
109
132
|
style={{
|
|
110
|
-
flexDirection: vertical ?
|
|
111
|
-
minHeight:
|
|
112
|
-
|
|
113
|
-
minWidth:
|
|
114
|
-
!React.Children.count(children) && !enabled ? '0px' : '46px',
|
|
133
|
+
flexDirection: vertical ? "column" : "row",
|
|
134
|
+
minHeight: !Children.count(children) && !enabled ? "0px" : "26px",
|
|
135
|
+
minWidth: !Children.count(children) && !enabled ? "0px" : "46px",
|
|
115
136
|
opacity: snapshot.isDraggingOver ? 0.8 : 1,
|
|
116
137
|
...(enabled ? editorStyle : style),
|
|
117
138
|
}}
|
|
118
|
-
|
|
139
|
+
onClick={handleClick}>
|
|
119
140
|
{childrenWithParentProps}
|
|
120
141
|
{provided.placeholder}
|
|
121
142
|
<div style={buttonStyle}>
|
|
122
143
|
<div
|
|
123
144
|
onClick={handleAlignChange}
|
|
124
145
|
style={{
|
|
125
|
-
cursor:
|
|
146
|
+
cursor: "pointer",
|
|
126
147
|
color: iconColor,
|
|
127
|
-
}}
|
|
128
|
-
>
|
|
148
|
+
}}>
|
|
129
149
|
<Icon
|
|
130
150
|
name={
|
|
131
|
-
align ===
|
|
151
|
+
align === "centered"
|
|
132
152
|
? vertical
|
|
133
|
-
?
|
|
134
|
-
:
|
|
135
|
-
: align ===
|
|
153
|
+
? "alignCenterV"
|
|
154
|
+
: "alignCenter"
|
|
155
|
+
: align === "end"
|
|
136
156
|
? vertical
|
|
137
|
-
?
|
|
138
|
-
:
|
|
157
|
+
? "alignEndV"
|
|
158
|
+
: "alignEnd"
|
|
139
159
|
: vertical
|
|
140
|
-
?
|
|
141
|
-
:
|
|
160
|
+
? "alignStartV"
|
|
161
|
+
: "alignStart"
|
|
142
162
|
}
|
|
143
163
|
/>
|
|
144
164
|
</div>
|
|
@@ -146,5 +166,5 @@ export default function GridArea({
|
|
|
146
166
|
</div>
|
|
147
167
|
)}
|
|
148
168
|
</Droppable>
|
|
149
|
-
);
|
|
169
|
+
) : null;
|
|
150
170
|
}
|
package/src/GridItem.tsx
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
CSSProperties,
|
|
4
|
-
useState,
|
|
5
|
-
useCallback,
|
|
6
|
-
ReactNode,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import { Draggable } from 'react-beautiful-dnd';
|
|
1
|
+
import { useMemo, CSSProperties, useState, useCallback, ReactNode } from "react";
|
|
2
|
+
import { Draggable } from "react-beautiful-dnd";
|
|
9
3
|
|
|
10
|
-
import { useAlignContext } from
|
|
11
|
-
import Icon from
|
|
12
|
-
import
|
|
4
|
+
import { useAlignContext } from "./context";
|
|
5
|
+
import Icon from "./Icon";
|
|
6
|
+
import "./grid.css";
|
|
13
7
|
|
|
14
8
|
export type ItemProps = {
|
|
15
9
|
className?: string;
|
|
@@ -48,11 +42,11 @@ export default function GridItem({
|
|
|
48
42
|
// Picky stuff.
|
|
49
43
|
style,
|
|
50
44
|
editorStyle,
|
|
51
|
-
iconColor =
|
|
45
|
+
iconColor = "rgb(255, 255, 255)",
|
|
52
46
|
...props
|
|
53
47
|
}: ItemProps) {
|
|
54
48
|
const { vertical } = props as {
|
|
55
|
-
|
|
49
|
+
startBottom?: boolean;
|
|
56
50
|
vertical?: boolean;
|
|
57
51
|
};
|
|
58
52
|
const { editing, isDragging, onExtend } = useAlignContext();
|
|
@@ -65,11 +59,11 @@ export default function GridItem({
|
|
|
65
59
|
|
|
66
60
|
const buttonStyles: CSSProperties = useMemo(
|
|
67
61
|
() => ({
|
|
68
|
-
alignItems:
|
|
69
|
-
float:
|
|
62
|
+
alignItems: "start",
|
|
63
|
+
float: "left",
|
|
70
64
|
color: iconColor,
|
|
71
65
|
}),
|
|
72
|
-
[iconColor]
|
|
66
|
+
[iconColor],
|
|
73
67
|
);
|
|
74
68
|
|
|
75
69
|
const ctx = useMemo(
|
|
@@ -83,7 +77,7 @@ export default function GridItem({
|
|
|
83
77
|
disabled,
|
|
84
78
|
index,
|
|
85
79
|
}),
|
|
86
|
-
[disabled, editing, extendable, extended, id, index, isDragging, isHovered]
|
|
80
|
+
[disabled, editing, extendable, extended, id, index, isDragging, isHovered],
|
|
87
81
|
);
|
|
88
82
|
|
|
89
83
|
return (
|
|
@@ -94,54 +88,39 @@ export default function GridItem({
|
|
|
94
88
|
{...provided.draggableProps}
|
|
95
89
|
className={`${className} item`}
|
|
96
90
|
style={{
|
|
97
|
-
flex: extended && !snapshot.isDragging ?
|
|
91
|
+
flex: extended && !snapshot.isDragging ? "auto" : undefined,
|
|
98
92
|
opacity: snapshot.isDragging ? 0.5 : 1,
|
|
99
93
|
...(editing ? editorStyle : style),
|
|
100
94
|
...provided.draggableProps.style,
|
|
101
|
-
}}
|
|
102
|
-
>
|
|
95
|
+
}}>
|
|
103
96
|
<div
|
|
104
97
|
style={{
|
|
105
|
-
display:
|
|
106
|
-
position:
|
|
107
|
-
minHeight: isHovered && !disabled ?
|
|
108
|
-
width: !vertical && extended ?
|
|
109
|
-
minWidth:
|
|
110
|
-
|
|
111
|
-
? extendable
|
|
112
|
-
? '70px'
|
|
113
|
-
: '35px'
|
|
114
|
-
: undefined,
|
|
115
|
-
height: vertical && extended ? '100%' : undefined,
|
|
98
|
+
display: "inline-block",
|
|
99
|
+
position: "relative",
|
|
100
|
+
minHeight: isHovered && !disabled ? "35px" : undefined,
|
|
101
|
+
width: !vertical && extended ? "100%" : undefined,
|
|
102
|
+
minWidth: isHovered && !disabled ? (extendable ? "70px" : "35px") : undefined,
|
|
103
|
+
height: vertical && extended ? "100%" : undefined,
|
|
116
104
|
}}
|
|
117
|
-
onMouseEnter={() => setHovered(true)}
|
|
118
|
-
onMouseLeave={() => setHovered(false)}
|
|
119
|
-
|
|
120
|
-
{typeof children ===
|
|
105
|
+
onMouseEnter={() => editing && setHovered(true)}
|
|
106
|
+
onMouseLeave={() => editing && setHovered(false)}
|
|
107
|
+
onClick={e => e.stopPropagation()}>
|
|
108
|
+
{typeof children === "function" ? children(ctx) : children}
|
|
121
109
|
<div
|
|
122
110
|
className="overlay"
|
|
123
111
|
style={{
|
|
124
112
|
display:
|
|
125
|
-
!disabled &&
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
? 'block'
|
|
130
|
-
: 'none',
|
|
131
|
-
}}
|
|
132
|
-
>
|
|
113
|
+
!disabled && editing && isHovered && (snapshot.isDragging || !isDragging)
|
|
114
|
+
? "block"
|
|
115
|
+
: "none",
|
|
116
|
+
}}>
|
|
133
117
|
<div className="overlay-buttons" style={buttonStyles}>
|
|
134
|
-
<div {...provided.dragHandleProps}>
|
|
118
|
+
<div {...provided.dragHandleProps} style={{ cursor: "grab" }}>
|
|
135
119
|
<Icon name="moveArrows" />
|
|
136
120
|
</div>
|
|
137
121
|
{extendable && (
|
|
138
|
-
<div
|
|
139
|
-
|
|
140
|
-
onClick={handleExtend}
|
|
141
|
-
>
|
|
142
|
-
<Icon
|
|
143
|
-
name={vertical ? 'verticalExtend' : 'horizontalExtend'}
|
|
144
|
-
/>
|
|
122
|
+
<div style={{ cursor: "pointer", marginLeft: "8px" }} onClick={handleExtend}>
|
|
123
|
+
<Icon name={vertical ? "verticalExtend" : "horizontalExtend"} />
|
|
145
124
|
</div>
|
|
146
125
|
)}
|
|
147
126
|
</div>
|
package/src/GridSection.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CSSProperties, ReactNode } from "react";
|
|
2
2
|
|
|
3
|
-
import { useAlignContext } from
|
|
4
|
-
import
|
|
3
|
+
import { useAlignContext } from "./context";
|
|
4
|
+
import "./grid.css";
|
|
5
5
|
|
|
6
6
|
export type GridSectionProps = {
|
|
7
7
|
className?: string;
|
|
@@ -29,23 +29,22 @@ const GridSection: React.FC<GridSectionProps> = ({
|
|
|
29
29
|
|
|
30
30
|
return (
|
|
31
31
|
<div
|
|
32
|
-
className={`section ${className} ${horizontal ?
|
|
33
|
-
stretch ?
|
|
32
|
+
className={`section ${className} ${horizontal ? "horizontal" : ""} ${
|
|
33
|
+
stretch ? "stretch" : ""
|
|
34
34
|
}`}
|
|
35
35
|
style={{
|
|
36
36
|
...(enabled ? editorStyle : style),
|
|
37
|
-
...(typeof fixedHeight ===
|
|
37
|
+
...(typeof fixedHeight === "number"
|
|
38
38
|
? {
|
|
39
|
-
height: fixedHeight +
|
|
39
|
+
height: fixedHeight + "px",
|
|
40
40
|
}
|
|
41
41
|
: {}),
|
|
42
|
-
...(typeof fixedWidth ===
|
|
42
|
+
...(typeof fixedWidth === "number"
|
|
43
43
|
? {
|
|
44
|
-
width: fixedWidth +
|
|
44
|
+
width: fixedWidth + "px",
|
|
45
45
|
}
|
|
46
46
|
: {}),
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
47
|
+
}}>
|
|
49
48
|
{children}
|
|
50
49
|
</div>
|
|
51
50
|
);
|