@movable/studio-framework 3.16.1-nick.4 → 3.17.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/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,14 +535,21 @@ 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
495
542
  } = tag;
543
+
544
+ if (tag.dynamicHref) {
545
+ onPendingPromise(getUnresolvedPropsCatch(propertyResolver, [tag.dynamicHref]));
546
+ }
547
+
496
548
  return /*#__PURE__*/React.createElement(StyledElement, {
497
549
  key: index,
498
550
  tag: tag,
499
- registryResolver: registryResolver
551
+ registryResolver: registryResolver,
552
+ resolveProperty: resolveProperty
500
553
  }, subtags ? /*#__PURE__*/React.createElement(Tags, {
501
554
  tags: subtags,
502
555
  canvas: canvas,
@@ -1900,11 +1953,46 @@ const getYPosition = justifyContent => {
1900
1953
  const RichTextSpan = ({
1901
1954
  attributes,
1902
1955
  insert,
1903
- fitToOneLine
1956
+ fitToOneLine,
1957
+ getPropertyWithFallback
1904
1958
  }) => {
1905
1959
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1960
+
1961
+ if (attributes && attributes.dynamicLink) {
1962
+ try {
1963
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1964
+ const href = getPropertyWithFallback?.(dynamicLinkData) || dynamicLinkData.propertyValue || dynamicLinkData.propertyFallback || null;
1965
+
1966
+ if (href) {
1967
+ const {
1968
+ dynamicLink,
1969
+ ...cleanAttributes
1970
+ } = attributes;
1971
+ const styles = {
1972
+ color: 'inherit',
1973
+ textDecoration: 'inherit',
1974
+ ...normalizeRichTextStyles(cleanAttributes),
1975
+ whiteSpace
1976
+ };
1977
+ const analyticsId = dynamicLinkData.analyticsId;
1978
+ return /*#__PURE__*/React.createElement("a", {
1979
+ href: href,
1980
+ target: "_parent",
1981
+ style: styles,
1982
+ "data-mi-analytics-id": analyticsId || undefined
1983
+ }, insert);
1984
+ }
1985
+ } catch (e) {// Parse error — fall through to render as span
1986
+ }
1987
+ }
1988
+
1989
+ const attrs = attributes || {};
1990
+ const {
1991
+ dynamicLink: _dl,
1992
+ ...cleanAttrs
1993
+ } = attrs;
1906
1994
  return /*#__PURE__*/React.createElement("span", {
1907
- style: { ...normalizeRichTextStyles(attributes),
1995
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1908
1996
  whiteSpace
1909
1997
  }
1910
1998
  }, insert);
@@ -1916,12 +2004,13 @@ const isNewLine = ({
1916
2004
 
1917
2005
  const haveSpans = spans => spans.length;
1918
2006
 
1919
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
2007
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React.createElement("br", {
1920
2008
  key: n
1921
2009
  }) : /*#__PURE__*/React.createElement(RichTextSpan, _extends({
1922
2010
  key: n
1923
2011
  }, span, {
1924
- fitToOneLine: fitToOneLine
2012
+ fitToOneLine: fitToOneLine,
2013
+ getPropertyWithFallback: getPropertyWithFallback
1925
2014
  })));
1926
2015
 
1927
2016
  class RichTextElement extends StudioTool {
@@ -2016,6 +2105,9 @@ class RichTextElement extends StudioTool {
2016
2105
  const {
2017
2106
  fitToOneLine = false
2018
2107
  } = this.props.tag;
2108
+ const {
2109
+ getPropertyWithFallback
2110
+ } = this.props;
2019
2111
  this.lastRichText = richTextStructure;
2020
2112
  const style = {
2021
2113
  fontSize: baseFontSize
@@ -2031,7 +2123,7 @@ class RichTextElement extends StudioTool {
2031
2123
  style: { ...attributes
2032
2124
  },
2033
2125
  key: i
2034
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React.createElement("br", null))));
2126
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React.createElement("br", null))));
2035
2127
  }
2036
2128
 
2037
2129
  }
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,14 +545,21 @@ 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
505
552
  } = tag;
553
+
554
+ if (tag.dynamicHref) {
555
+ onPendingPromise(getUnresolvedPropsCatch(propertyResolver, [tag.dynamicHref]));
556
+ }
557
+
506
558
  return /*#__PURE__*/React__default['default'].createElement(StyledElement, {
507
559
  key: index,
508
560
  tag: tag,
509
- registryResolver: registryResolver
561
+ registryResolver: registryResolver,
562
+ resolveProperty: resolveProperty
510
563
  }, subtags ? /*#__PURE__*/React__default['default'].createElement(Tags, {
511
564
  tags: subtags,
512
565
  canvas: canvas,
@@ -1910,11 +1963,46 @@ const getYPosition = justifyContent => {
1910
1963
  const RichTextSpan = ({
1911
1964
  attributes,
1912
1965
  insert,
1913
- fitToOneLine
1966
+ fitToOneLine,
1967
+ getPropertyWithFallback
1914
1968
  }) => {
1915
1969
  const whiteSpace = fitToOneLine ? 'nowrap' : 'pre-wrap';
1970
+
1971
+ if (attributes && attributes.dynamicLink) {
1972
+ try {
1973
+ const dynamicLinkData = typeof attributes.dynamicLink === 'string' ? JSON.parse(attributes.dynamicLink) : attributes.dynamicLink;
1974
+ const href = getPropertyWithFallback?.(dynamicLinkData) || dynamicLinkData.propertyValue || dynamicLinkData.propertyFallback || null;
1975
+
1976
+ if (href) {
1977
+ const {
1978
+ dynamicLink,
1979
+ ...cleanAttributes
1980
+ } = attributes;
1981
+ const styles = {
1982
+ color: 'inherit',
1983
+ textDecoration: 'inherit',
1984
+ ...normalizeRichTextStyles(cleanAttributes),
1985
+ whiteSpace
1986
+ };
1987
+ const analyticsId = dynamicLinkData.analyticsId;
1988
+ return /*#__PURE__*/React__default['default'].createElement("a", {
1989
+ href: href,
1990
+ target: "_parent",
1991
+ style: styles,
1992
+ "data-mi-analytics-id": analyticsId || undefined
1993
+ }, insert);
1994
+ }
1995
+ } catch (e) {// Parse error — fall through to render as span
1996
+ }
1997
+ }
1998
+
1999
+ const attrs = attributes || {};
2000
+ const {
2001
+ dynamicLink: _dl,
2002
+ ...cleanAttrs
2003
+ } = attrs;
1916
2004
  return /*#__PURE__*/React__default['default'].createElement("span", {
1917
- style: { ...normalizeRichTextStyles(attributes),
2005
+ style: { ...normalizeRichTextStyles(cleanAttrs),
1918
2006
  whiteSpace
1919
2007
  }
1920
2008
  }, insert);
@@ -1926,12 +2014,13 @@ const isNewLine = ({
1926
2014
 
1927
2015
  const haveSpans = spans => spans.length;
1928
2016
 
1929
- const mapSpans = (spans, fitToOneLine) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
2017
+ const mapSpans = (spans, fitToOneLine, getPropertyWithFallback) => spans.map((span, n) => isNewLine(span) ? /*#__PURE__*/React__default['default'].createElement("br", {
1930
2018
  key: n
1931
2019
  }) : /*#__PURE__*/React__default['default'].createElement(RichTextSpan, _extends({
1932
2020
  key: n
1933
2021
  }, span, {
1934
- fitToOneLine: fitToOneLine
2022
+ fitToOneLine: fitToOneLine,
2023
+ getPropertyWithFallback: getPropertyWithFallback
1935
2024
  })));
1936
2025
 
1937
2026
  class RichTextElement extends StudioTool {
@@ -2026,6 +2115,9 @@ class RichTextElement extends StudioTool {
2026
2115
  const {
2027
2116
  fitToOneLine = false
2028
2117
  } = this.props.tag;
2118
+ const {
2119
+ getPropertyWithFallback
2120
+ } = this.props;
2029
2121
  this.lastRichText = richTextStructure;
2030
2122
  const style = {
2031
2123
  fontSize: baseFontSize
@@ -2041,7 +2133,7 @@ class RichTextElement extends StudioTool {
2041
2133
  style: { ...attributes
2042
2134
  },
2043
2135
  key: i
2044
- }, haveSpans(spans) ? mapSpans(spans, fitToOneLine) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2136
+ }, haveSpans(spans) ? mapSpans(spans, fitToOneLine, getPropertyWithFallback) : /*#__PURE__*/React__default['default'].createElement("br", null))));
2045
2137
  }
2046
2138
 
2047
2139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movable/studio-framework",
3
- "version": "3.16.1-nick.4+13f059aa",
3
+ "version": "3.17.0",
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.1-nick.4+13f059aa",
35
- "@movable/studio-framework-test-helpers": "^3.16.1-nick.4+13f059aa",
34
+ "@movable/framework-types": "^3.17.0",
35
+ "@movable/studio-framework-test-helpers": "^3.17.0",
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": "13f059aa8c50c786d92859c771474e9753babced"
69
+ "gitHead": "da179f4d7c862ed7d49d0515f7d6a6116eb6e6ae"
70
70
  }