@movable/studio-framework 3.16.0 → 3.16.1-canary.18

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/index.es.js CHANGED
@@ -146,13 +146,36 @@ class StyledElement extends React.Component {
146
146
  this.updateStyleElement();
147
147
  }
148
148
 
149
+ componentDidUpdate() {
150
+ this.updateStyleElement();
151
+ }
152
+
149
153
  render() {
150
154
  const {
151
155
  tag,
152
- children
156
+ children,
157
+ resolveProperty
153
158
  } = this.props;
154
159
  const style = styleFromAttributes(tag);
155
160
  const className = classNameFromAttributes(tag);
161
+ const href = resolveProperty && tag.dynamicHref ? resolveProperty(tag.dynamicHref) : null;
162
+
163
+ if (href) {
164
+ const analyticsId = tag.dynamicHref?.analyticsId;
165
+ return /*#__PURE__*/React.createElement("a", {
166
+ className: className,
167
+ style: {
168
+ textDecoration: 'none',
169
+ color: 'inherit',
170
+ ...style
171
+ },
172
+ href: href,
173
+ target: "_parent",
174
+ "data-mi-analytics-id": analyticsId || undefined,
175
+ ref: this.setStyleElementRef
176
+ }, children);
177
+ }
178
+
156
179
  return /*#__PURE__*/React.createElement("div", {
157
180
  className: className,
158
181
  style: style,
@@ -480,6 +503,29 @@ class TagComponent extends React.Component {
480
503
 
481
504
  }
482
505
 
506
+ function makeResolveProperty(propertyResolver) {
507
+ return function resolveProperty(prop) {
508
+ if (!prop) return null;
509
+
510
+ if (prop.propertyValue) {
511
+ return prop.propertyValue;
512
+ }
513
+
514
+ const {
515
+ propertyPath,
516
+ context,
517
+ propertyGroupKey = false
518
+ } = prop;
519
+ const [result] = propertyResolver.getPropertyStateTuple(propertyGroupKey, propertyPath, context);
520
+
521
+ if (result !== null && typeof result !== 'undefined' && result !== '') {
522
+ return result;
523
+ }
524
+
525
+ return prop.propertyFallback || null;
526
+ };
527
+ }
528
+
483
529
  class Tags extends React.Component {
484
530
  render() {
485
531
  const {
@@ -489,6 +535,7 @@ class Tags extends React.Component {
489
535
  tags,
490
536
  canvas
491
537
  } = this.props;
538
+ const resolveProperty = makeResolveProperty(propertyResolver);
492
539
  return tags.map((tag, index) => {
493
540
  const {
494
541
  subtags
@@ -496,7 +543,8 @@ class Tags extends React.Component {
496
543
  return /*#__PURE__*/React.createElement(StyledElement, {
497
544
  key: index,
498
545
  tag: tag,
499
- registryResolver: registryResolver
546
+ registryResolver: registryResolver,
547
+ resolveProperty: resolveProperty
500
548
  }, subtags ? /*#__PURE__*/React.createElement(Tags, {
501
549
  tags: subtags,
502
550
  canvas: canvas,
@@ -1900,11 +1948,54 @@ const getYPosition = justifyContent => {
1900
1948
  const RichTextSpan = ({
1901
1949
  attributes,
1902
1950
  insert,
1903
- fitToOneLine
1951
+ fitToOneLine,
1952
+ getPropertyWithFallback
1904
1953
  }) => {
1905
1954
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1955
+
1956
+ if (attributes && attributes.dynamicLink) {
1957
+ try {
1958
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1959
+ let href = null;
1960
+
1961
+ if (dynamicLinkData.propertyValue) {
1962
+ href = dynamicLinkData.propertyValue;
1963
+ } else if (getPropertyWithFallback) {
1964
+ href = getPropertyWithFallback(dynamicLinkData);
1965
+ } else if (dynamicLinkData.propertyFallback) {
1966
+ href = dynamicLinkData.propertyFallback;
1967
+ }
1968
+
1969
+ if (href) {
1970
+ const {
1971
+ dynamicLink,
1972
+ ...cleanAttributes
1973
+ } = attributes;
1974
+ const styles = {
1975
+ color: 'inherit',
1976
+ textDecoration: 'inherit',
1977
+ ...normalizeRichTextStyles(cleanAttributes),
1978
+ whiteSpace
1979
+ };
1980
+ const analyticsId = dynamicLinkData.analyticsId;
1981
+ return /*#__PURE__*/React.createElement("a", {
1982
+ href: href,
1983
+ target: "_parent",
1984
+ style: styles,
1985
+ "data-mi-analytics-id": analyticsId || undefined
1986
+ }, insert);
1987
+ }
1988
+ } catch (e) {// Parse error — fall through to render as span
1989
+ }
1990
+ }
1991
+
1992
+ const attrs = attributes || {};
1993
+ const {
1994
+ dynamicLink: _dl,
1995
+ ...cleanAttrs
1996
+ } = attrs;
1906
1997
  return /*#__PURE__*/React.createElement("span", {
1907
- style: { ...normalizeRichTextStyles(attributes),
1998
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1908
1999
  whiteSpace
1909
2000
  }
1910
2001
  }, insert);
@@ -1916,12 +2007,13 @@ const isNewLine = ({
1916
2007
 
1917
2008
  const haveSpans = spans => spans.length;
1918
2009
 
1919
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
2010
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
1920
2011
  key: n
1921
2012
  }) : /*#__PURE__*/React.createElement(RichTextSpan, _extends({
1922
2013
  key: n
1923
2014
  }, span, {
1924
- fitToOneLine: fitToOneLine
2015
+ fitToOneLine: fitToOneLine,
2016
+ getPropertyWithFallback: getPropertyWithFallback
1925
2017
  })));
1926
2018
 
1927
2019
  class RichTextElement extends StudioTool {
@@ -2016,6 +2108,9 @@ class RichTextElement extends StudioTool {
2016
2108
  const {
2017
2109
  fitToOneLine = false
2018
2110
  } = this.props.tag;
2111
+ const {
2112
+ getPropertyWithFallback
2113
+ } = this.props;
2019
2114
  this.lastRichText = richTextStructure;
2020
2115
  const style = {
2021
2116
  fontSize: baseFontSize
@@ -2031,7 +2126,7 @@ class RichTextElement extends StudioTool {
2031
2126
  style: { ...attributes
2032
2127
  },
2033
2128
  key: i
2034
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React.createElement("br", null))));
2129
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React.createElement("br", null))));
2035
2130
  }
2036
2131
 
2037
2132
  }
package/dist/index.js CHANGED
@@ -156,13 +156,36 @@ class StyledElement extends React__default['default'].Component {
156
156
  this.updateStyleElement();
157
157
  }
158
158
 
159
+ componentDidUpdate() {
160
+ this.updateStyleElement();
161
+ }
162
+
159
163
  render() {
160
164
  const {
161
165
  tag,
162
- children
166
+ children,
167
+ resolveProperty
163
168
  } = this.props;
164
169
  const style = styleFromAttributes(tag);
165
170
  const className = classNameFromAttributes(tag);
171
+ const href = resolveProperty && tag.dynamicHref ? resolveProperty(tag.dynamicHref) : null;
172
+
173
+ if (href) {
174
+ const analyticsId = tag.dynamicHref?.analyticsId;
175
+ return /*#__PURE__*/React__default['default'].createElement("a", {
176
+ className: className,
177
+ style: {
178
+ textDecoration: 'none',
179
+ color: 'inherit',
180
+ ...style
181
+ },
182
+ href: href,
183
+ target: "_parent",
184
+ "data-mi-analytics-id": analyticsId || undefined,
185
+ ref: this.setStyleElementRef
186
+ }, children);
187
+ }
188
+
166
189
  return /*#__PURE__*/React__default['default'].createElement("div", {
167
190
  className: className,
168
191
  style: style,
@@ -490,6 +513,29 @@ class TagComponent extends React__default['default'].Component {
490
513
 
491
514
  }
492
515
 
516
+ function makeResolveProperty(propertyResolver) {
517
+ return function resolveProperty(prop) {
518
+ if (!prop) return null;
519
+
520
+ if (prop.propertyValue) {
521
+ return prop.propertyValue;
522
+ }
523
+
524
+ const {
525
+ propertyPath,
526
+ context,
527
+ propertyGroupKey = false
528
+ } = prop;
529
+ const [result] = propertyResolver.getPropertyStateTuple(propertyGroupKey, propertyPath, context);
530
+
531
+ if (result !== null && typeof result !== 'undefined' && result !== '') {
532
+ return result;
533
+ }
534
+
535
+ return prop.propertyFallback || null;
536
+ };
537
+ }
538
+
493
539
  class Tags extends React__default['default'].Component {
494
540
  render() {
495
541
  const {
@@ -499,6 +545,7 @@ class Tags extends React__default['default'].Component {
499
545
  tags,
500
546
  canvas
501
547
  } = this.props;
548
+ const resolveProperty = makeResolveProperty(propertyResolver);
502
549
  return tags.map((tag, index) => {
503
550
  const {
504
551
  subtags
@@ -506,7 +553,8 @@ class Tags extends React__default['default'].Component {
506
553
  return /*#__PURE__*/React__default['default'].createElement(StyledElement, {
507
554
  key: index,
508
555
  tag: tag,
509
- registryResolver: registryResolver
556
+ registryResolver: registryResolver,
557
+ resolveProperty: resolveProperty
510
558
  }, subtags ? /*#__PURE__*/React__default['default'].createElement(Tags, {
511
559
  tags: subtags,
512
560
  canvas: canvas,
@@ -1910,11 +1958,54 @@ const getYPosition = justifyContent => {
1910
1958
  const RichTextSpan = ({
1911
1959
  attributes,
1912
1960
  insert,
1913
- fitToOneLine
1961
+ fitToOneLine,
1962
+ getPropertyWithFallback
1914
1963
  }) => {
1915
1964
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1965
+
1966
+ if (attributes && attributes.dynamicLink) {
1967
+ try {
1968
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1969
+ let href = null;
1970
+
1971
+ if (dynamicLinkData.propertyValue) {
1972
+ href = dynamicLinkData.propertyValue;
1973
+ } else if (getPropertyWithFallback) {
1974
+ href = getPropertyWithFallback(dynamicLinkData);
1975
+ } else if (dynamicLinkData.propertyFallback) {
1976
+ href = dynamicLinkData.propertyFallback;
1977
+ }
1978
+
1979
+ if (href) {
1980
+ const {
1981
+ dynamicLink,
1982
+ ...cleanAttributes
1983
+ } = attributes;
1984
+ const styles = {
1985
+ color: 'inherit',
1986
+ textDecoration: 'inherit',
1987
+ ...normalizeRichTextStyles(cleanAttributes),
1988
+ whiteSpace
1989
+ };
1990
+ const analyticsId = dynamicLinkData.analyticsId;
1991
+ return /*#__PURE__*/React__default['default'].createElement("a", {
1992
+ href: href,
1993
+ target: "_parent",
1994
+ style: styles,
1995
+ "data-mi-analytics-id": analyticsId || undefined
1996
+ }, insert);
1997
+ }
1998
+ } catch (e) {// Parse error — fall through to render as span
1999
+ }
2000
+ }
2001
+
2002
+ const attrs = attributes || {};
2003
+ const {
2004
+ dynamicLink: _dl,
2005
+ ...cleanAttrs
2006
+ } = attrs;
1916
2007
  return /*#__PURE__*/React__default['default'].createElement("span", {
1917
- style: { ...normalizeRichTextStyles(attributes),
2008
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1918
2009
  whiteSpace
1919
2010
  }
1920
2011
  }, insert);
@@ -1926,12 +2017,13 @@ const isNewLine = ({
1926
2017
 
1927
2018
  const haveSpans = spans => spans.length;
1928
2019
 
1929
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
2020
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
1930
2021
  key: n
1931
2022
  }) : /*#__PURE__*/React__default['default'].createElement(RichTextSpan, _extends({
1932
2023
  key: n
1933
2024
  }, span, {
1934
- fitToOneLine: fitToOneLine
2025
+ fitToOneLine: fitToOneLine,
2026
+ getPropertyWithFallback: getPropertyWithFallback
1935
2027
  })));
1936
2028
 
1937
2029
  class RichTextElement extends StudioTool {
@@ -2026,6 +2118,9 @@ class RichTextElement extends StudioTool {
2026
2118
  const {
2027
2119
  fitToOneLine = false
2028
2120
  } = this.props.tag;
2121
+ const {
2122
+ getPropertyWithFallback
2123
+ } = this.props;
2029
2124
  this.lastRichText = richTextStructure;
2030
2125
  const style = {
2031
2126
  fontSize: baseFontSize
@@ -2041,7 +2136,7 @@ class RichTextElement extends StudioTool {
2041
2136
  style: { ...attributes
2042
2137
  },
2043
2138
  key: i
2044
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2139
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2045
2140
  }
2046
2141
 
2047
2142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movable/studio-framework",
3
- "version": "3.16.0",
3
+ "version": "3.16.1-canary.18+0e7ee126",
4
4
  "description": "A Component library for reactive Studio apps.",
5
5
  "author": "Movable Ink",
6
6
  "repository": "movableink/studio-framework",
@@ -31,8 +31,8 @@
31
31
  "@babel/preset-react": "^7.14.5",
32
32
  "@babel/preset-typescript": "^7.13.0",
33
33
  "@movable/eslint-config-react": "^1.0.1",
34
- "@movable/framework-types": "^3.16.0",
35
- "@movable/studio-framework-test-helpers": "^3.16.0",
34
+ "@movable/framework-types": "^3.16.1-canary.18+0e7ee126",
35
+ "@movable/studio-framework-test-helpers": "^3.16.1-canary.18+0e7ee126",
36
36
  "@types/qunit": "^2.11.1",
37
37
  "@types/qunit-dom": "^0.7.0",
38
38
  "@types/react": "^17.0.6",
@@ -66,5 +66,5 @@
66
66
  "volta": {
67
67
  "extends": "../../package.json"
68
68
  },
69
- "gitHead": "26c6ba756981e2b44d0703141daab6eda214a75d"
69
+ "gitHead": "0e7ee12614124ce01498aa9dafb8cb2b240b719b"
70
70
  }